Be careful with copy paste: Encoding hell

Submitted by John on Fri, 01/20/2017 - 11:19

I shouldn't have to say this to the type of person who follows this site, which is mostly myself, and a bunch of trump supporting Russians that speak very strange languages... but here is a reminder to be careful when copy-pasting code, especially from comments/descriptions from a ticketing system. Depending on your operating system, the following lines will look identical, but there is a subtle difference. 


  if (true) {
    $foo = 'bar';
  }

  if (true) {
    
$foo = 'bar';
  }

I know Linux users will likely see the error right away because of the characters that OS usually handles. The error is in the second if statement. It uses U+2028 (LINE SEPARATOR), instead of a regular line feed.  U+000a.

Lesson learned... again. It's always a good practice to re-type code. If anything, it is good practice in thoroughly examining the code instead of whole-sale copy-pasting. 

Tags