netzke / netzke-core

Framework for Sencha Ext JS + Ruby on Rails client-server components
http://netzke.org
Other
263 stars 77 forks source link

'//' in form_authenticity_token causes unterminated string literal #43

Closed scho closed 11 years ago

scho commented 12 years ago

Hi,

today I ran into a strange behaviour of netzke. Whenever the form_authenticity_token contains two slashes ('//') the site won't load because of a JavaScript error "SyntaxError: unterminated string literal".

Here's an example:

form_authenticity_token = "Mns6XnkQVAVsBnUi8hoELD5y1jhMnLuSa+z/fax//3s="

ends up with the following netzke/ext.js

Ext.Ajax.extraParams = {authenticity_token: 'Mns6XnkQVAVsBnUi8hoELD5y1jhMnLuSa+z/fax
...

It only happens in production, so gues it has something to do with removing comments in JS files. A 'correct' version of netzke/ext.js looks like the following in my case (without a comment at the end of the line):

Ext.Ajax.extraParams = {authenticity_token: 's9ajCtifhGq9qR4WopH7r0QCCnydQxRPd2tLO8HeVCE='}; 
Ext.ns('Netzke');

Here are my gems: https://gist.github.com/3235417 I use ruby 1.9.3

EDIT: I've just found out that most likely String#strip_js_comments causes the problem. I guess Uglifier would do the trick, but that would also introduce another dependency :( https://github.com/lautis/uglifier

Maybe something like this could solve it:

begin
  # Use uglifier here
rescue LoadError
  # No Uglifier => fallback to strip_js_comments (or don't do anything)
end
mxgrn commented 12 years ago

Thank you for this one, I'll experiment with uglifier and will come up with something before the next release.

scho commented 11 years ago

I've just stumbled across this issue. As far as I can see it, this isn't fixed yet, is it?

mxgrn commented 11 years ago

Somehow I missed your fix back then, sorry! I just released 0.8.1 with it, thanks a bunch!