Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Broken escape_javascript after SafeBuffer modifications in rails 3.0.8 #1553

Closed
morgoth opened this issue Jun 8, 2011 · 10 comments
Closed

Comments

@morgoth
Copy link
Member

morgoth commented Jun 8, 2011

After this commit: 53a2c0b
(in rails 3-0-stable branch and present in rails 3.0.8)
javascript_escape connected with rendering template is not working correctly.

<%= escape_javascript(render("partial")) %>

Partial content:

<span> Topics </span>

Results:
rails 3.0.8:

"<span> Topics span>"

rails 3.0.7:

"<span> Topics <\\/span>\\n"

You can play with this bug using sample app: https://github.com/morgoth/escape_javascript_bug

@morgoth
Copy link
Member Author

morgoth commented Jun 8, 2011

related to #1555

@josevalim
Copy link
Contributor

escape_javascript needs to be fixed to not use $1.

@sekrett
Copy link
Contributor

sekrett commented Jun 8, 2011

Same problem here

@tardate
Copy link
Contributor

tardate commented Jun 8, 2011

@josevalim that's what we're doing as a monkey-patch to get by for now, however it means gsub's behaviour remains changed from ruby core doc.. not too comfortable with that. I'm trying to find a good fix to suggest on 1555.

@josevalim
Copy link
Contributor

@tardate I don't think we can leave gsub intact. If it cannot work as in core, we will probably remove it straight away. that's why I suggest to change escape_javascript to fix the issue differently. :)

@starpeak
Copy link

starpeak commented Jun 8, 2011

As a quick workaround you can write an initializer monkey-patching escape_javascript:

module ActionView::Helpers::JavaScriptHelper
  def escape_javascript_with_workaround(javascript)
    escape_javascript_without_workaround(javascript.try(:to_str)).html_safe
  end

  alias_method_chain :escape_javascript, :workaround
end

@madwire
Copy link

madwire commented Jun 8, 2011

same issue on 3.1.0.rc2

@josevalim
Copy link
Contributor

Fixed on #1558.

@diogui
Copy link

diogui commented Jun 25, 2011

Hi. I'm just starting wiht rails 3.0.8. and I came across with the same problem ... Starpeak where should I put that monkey-patching escape_javascript ? Thanks for your help and Keep on the good work guys ! Amazing chages from Rails 1 to now . Rails is getting better and better :)

@diogui
Copy link

diogui commented Jun 25, 2011

I've update to the 3.0.9 version :) Wroking perfect :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

7 participants