This project is archived and is in readonly mode.

#5138 ✓resolved
Andrew Kaspick

[PATCH] Fix generated html for remote_function so that ampersands can be used in passed in options

Reported by Andrew Kaspick | July 17th, 2010 @ 09:44 AM | in 3.x

The following code before this patch produced the following html...

<%=
tmp = "'object[name]=' + result + '&object[attr1]=' + attr1 + '&object[attr2]=' + attr2"
remote_function :url => objects_path, :method => :post,
  :with => tmp.html_safe
%>
new Ajax.Request('/objects', {
  asynchronous:true, evalScripts:true, method:'post',
  parameters:
    'object[name]=' + result + '&amp;object[attr1]=' + 
    attr1 + '&amp;object[attr2]=' + attr2 + '&amp;authenticity_token=' +
    encodeURIComponent('YAq5IJ6Cbfcy3Faebh3gJFKXiba9L87RB0i7m2fEmpg=')
})

Note the escaping of &'s to &amp;

Without the patch the entire "Ajax..." string is unsafe due to concatenations of various options and strings even if we pass our parameter string as html_safe; an html_safe string concatenated with an unsafe string results in an unsafe string. Since our end result will always be an unsafe string the resulting javascript is escaped causing the invalid results to be produced.

With the patch, because the entire javascript string is made html_safe, we don't need to specify html_safe for our own string, so the following code...

<%=
remote_function :url => objects_path, :method => :post,
  :with => "'object[name]=' + result + '&object[attr1]=' + attr1 + '&object[attr]=' + attr2"
%>

now results in the correct output of...

new Ajax.Request('/objects', {
  asynchronous:true, evalScripts:true, method:'post',
  parameters:
    'object[name]=' + result + '&object[attr1]=' + attr1 + 
    '&object[attr2]=' + attr2 + '&authenticity_token=' +
    encodeURIComponent('YAq5IJ6Cbfcy3Faebh3gJFKXiba9L87RB0i7m2fEmpg=')
})

Comments and changes to this ticket

Create your profile

Help contribute to this project by taking a few moments to create your personal profile. Create your profile »

<h2 style="font-size: 14px">Tickets have moved to Github</h2>

The new ticket tracker is available at <a href="https://github.com/rails/rails/issues">https://github.com/rails/rails/issues</a>

Attachments

Pages