Ticket #268 - potential fix to whitespace issues

Here's the proposed fix. I've tested against all our target browsers (personal eyeball tests and unit tests), and have it staged for production in my deployment as a hotfix.

I will not be writing unit tests, as I'm currently a bit busy, but I have posted recommendations for unit tests you may want to write in #268, should you want to start testing this behaviour.