public
Description: Ruby on Rails
Homepage: http://rubyonrails.org
Clone URL: git://github.com/rails/rails.git
Ensure observe_field encodes value parameter. [#216 state:resolved]

Signed-off-by: Pratik Naik <pratiknaik@gmail.com>
fcheung (author)
Sat May 17 11:12:36 -0700 2008
lifo (committer)
Mon May 19 02:30:56 -0700 2008
commit  17d1319c480e58e28641b243da50ae5e5eab89dc
tree    511ad2ba892080ec6bd05b9e3659dd326bb18906
parent  c1c1d6c2ea72424dfae0b5ee1991d904dcf0f252
...
1068
1069
1070
1071
 
1072
1073
1074
...
1068
1069
1070
 
1071
1072
1073
1074
0
@@ -1068,7 +1068,7 @@ module ActionView
0
     
0
       def build_observer(klass, name, options = {})
0
         if options[:with] && (options[:with] !~ /[\{=(.]/)
0
-          options[:with] = "'#{options[:with]}=' + value"
0
+          options[:with] = "'#{options[:with]}=' + encodeURIComponent(value)"
0
         else
0
           options[:with] ||= 'value' unless options[:function]
0
         end
...
219
220
221
222
 
223
224
 
225
226
227
...
219
220
221
 
222
223
 
224
225
226
227
0
@@ -219,9 +219,9 @@ class PrototypeHelperTest < PrototypeHelperBaseTest
0
   end
0
   
0
   def test_observe_field_using_with_option
0
-    expected = %(<script type=\"text/javascript\">\n//<![CDATA[\nnew Form.Element.Observer('glass', 300, function(element, value) {new Ajax.Request('http://www.example.com/check_value', {asynchronous:true, evalScripts:true, parameters:'id=' + value})})\n//]]>\n</script>)
0
+    expected = %(<script type=\"text/javascript\">\n//<![CDATA[\nnew Form.Element.Observer('glass', 300, function(element, value) {new Ajax.Request('http://www.example.com/check_value', {asynchronous:true, evalScripts:true, parameters:'id=' + encodeURIComponent(value)})})\n//]]>\n</script>)
0
     assert_dom_equal expected, observe_field("glass", :frequency => 5.minutes, :url => { :action => "check_value" }, :with => 'id')
0
-    assert_dom_equal expected, observe_field("glass", :frequency => 5.minutes, :url => { :action => "check_value" }, :with => "'id=' + value")
0
+    assert_dom_equal expected, observe_field("glass", :frequency => 5.minutes, :url => { :action => "check_value" }, :with => "'id=' + encodeURIComponent(value)")
0
   end
0
   
0
   def test_observe_field_using_json_in_with_option

Comments