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

Generated page_update javascript is incorrectly escaped. #17

Open
esb opened this issue Jan 10, 2013 · 2 comments
Open

Generated page_update javascript is incorrectly escaped. #17

esb opened this issue Jan 10, 2013 · 2 comments

Comments

@esb
Copy link

esb commented Jan 10, 2013

The javascript being generated by update_page is incorrectly marked as html_safe. This causes a problem when you include an update_page fragment as an option on an HTML tag.

For example:

<%= submit_tag('Save', :disable_with => 'Please wait...', :onclick => update_page {|p| p.hide("cancel-update")}) %>

The onclick option is passed through to the tag helpers and eventually the text is processed by ERB::Util.html_escape. However, the html_escape method does not escape the string if it is marked as html_safe. All output from update_page is marked as html_safe, even though it isn't.

The output from update_page in the above example is

"Element.hide(\"cancel-update\");"

Clearly, the output has not been escaped as the " characters have not been converted -

"Element.hide(&quot;cancel-update&quot;);"

The solution is to remove the html_safe method from the output of update_page -

def update_page(&block)
  JavaScriptGenerator.new(self, &block).to_s
end

I realize that it's pretty futile raising an issue here in the hope that the official gem might be updated. However, for any other users out there with large amounts of Prototype code that can't afford to instantly convert everything to JQuery, then this might help you.

It would be nice if the Rails developers sometimes recognized that in the real world, we don't necessarily have all the resources to instantly jump on the latest bandwagon. Sadly Prototype has fallen out of favour and has now been neglected to the point where nobody bothers to fix any errors.

@fxn
Copy link
Member

fxn commented Jan 10, 2013

Hi @esb while we do not actively maintain this gem, if you provide a patch that fixes the issue we will apply.

@esb
Copy link
Author

esb commented Jan 10, 2013

Thanks for the update. I'll generate some test cases for it tomorrow.

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

2 participants