问题
I just asked a question about an "Illegal Character" in my javascript.

The answer there led me to find that there is a problem with compressing javascript in the Rails asset pipeline inserting various Illegal Characters.
The error I was receiving in the post was:
SyntaxError: Invalid character '\u0008'
I found that not using compression caused this to go away completely... but I want compression! That error was found using the Rails default uglifer
gem. I thought maybe it was a bug with that particular compression gem so I tried using other compressors as directed on the Rails docs. I got very similar, but different errors:
Uglifier: SyntaxError: Invalid character '\u0008'
Closure: SyntaxError: Invalid character '\u0190'
YUI: SyntaxError: Invalid character '\u0025'
I tried looking at the minimized code for these, but because the "Invalid character" is different each time, it is leading me to believe something else is the problem.
Here is an example compressed JS file. Can anybody point me in the right direction here?
回答1:
It seems as though you're using \b
in some of your JavaScript regex, which I believe isn't supported. Try replacing \b
with \u0008
, E.x.
string.replace(/\u0008/g, '\\b')
来源:https://stackoverflow.com/questions/10354420/rails-asset-pipeline-js-compression-inserting-illegal-characters