Hidden Characters in Safari’s Copy-and-Paste Caused Site Errors

Earlier today, (well technically it was yesterday) I installed the Acronym Replacer WordPress plugin and had my whole site crash with a PHP parse error. I immediately deactivated the plugin, and everything was fine. I spent the next half hour reviewing the code, and upon finding no apparent problems that would have caused such an obvious error, I spent the following half hour searching the Internet for possible causes. As it turns out, it was really quite simple. Thanks to Dave over at ForbiddenByte I was able to solve the problem in minutes!

It turns out that Safari has a nasty little bug that causes text that you copy to contain invisible characters, referred to as “gremlins,” which are copied right along with the text. This means that when you select and copy code fragments, then paste them right into a source file such as PHP script in my case those gremlins come right along with the code and confuse the hell out of the computer.

The solution then is not to use Safari for copying code. I fired up Firefox, copied the source code for the plugin, pasted it right into my site and bam! No problems.

I’m hoping this entry might save someone the aggravation that I could have gone through, if it weren’t for Dave. That’s the beauty of community, really. The wonder of the Web.

2 replies on “Hidden Characters in Safari’s Copy-and-Paste Caused Site Errors”

  1. You should be able to remove nested acronym tags fairly simply: If you look in the code, you’ll see I cheat a little and use two regular expressions… The second regex is a ‘fix’ regex which removes acronym tags from within other tags. That is: the initial regex is too agressive so I fix it by checking for acronyms inside angle brackets. Anyway, you could fix your situation in a similar way with a third line:

    $text = preg_replace(
    "|<acronym[^>]*><acronym title="$description">$acronym</acronym></acronym>|imsU",
    "<acronym title="$description">$acronym</acronym>" , $text);

    That should do it [:)] , but I haven’t really tested it …

Comments are closed.