Rails Asset Pipeline JS Compression Inserting “Illegal Characters”

别等时光非礼了梦想. 提交于 2019-12-13 04:45:29

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!