Rails Asset Pipeline JS Compression Inserting“Illegal Characters” [英] Rails Asset Pipeline JS Compression Inserting "Illegal Characters"
问题描述
我。我有非常相似,但不同的错误:
Uglifier:SyntaxError:无效字符'\\\'
Closure:语法错误:无效字符'\\\Ɛ'
YUI:SyntaxError:无效字符'\\\%'
看起来好像你在使用 \\ b
在某些JavaScript正则表达式,我相信是不支持。尝试将 \b
替换为 \\\
,例如
string.replace(/ \\\ / g,'\\b')
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?
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')
这篇关于Rails Asset Pipeline JS Compression Inserting“Illegal Characters”的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!