Skip to content
This repository
Browse code

fix escaping id and parameters in path [#5137 state:resolved]

Signed-off-by: José Valim <jose.valim@gmail.com>
  • Loading branch information...
commit 0e969bdaf8ff2e3384350687aa0b583f94d6dfbc 1 parent 78c8242
Josef Reidinger authored July 22, 2010 josevalim committed July 26, 2010
4  activeresource/lib/active_resource/base.rb
@@ -577,7 +577,7 @@ def prefix_source
577 577
       # Default value is <tt>site.path</tt>.
578 578
       def prefix=(value = '/')
579 579
         # Replace :placeholders with '#{embedded options[:lookups]}'
580  
-        prefix_call = value.gsub(/:\w+/) { |key| "\#{options[#{key}]}" }
  580
+        prefix_call = value.gsub(/:\w+/) { |key| "\#{URI.escape options[#{key}].to_s}" }
581 581
 
582 582
         # Clear prefix parameters in case they have been cached
583 583
         @prefix_parameters = nil
@@ -622,7 +622,7 @@ def prefix(options={}) "#{prefix_call}" end
622 622
       #
623 623
       def element_path(id, prefix_options = {}, query_options = nil)
624 624
         prefix_options, query_options = split_options(prefix_options) if query_options.nil?
625  
-        "#{prefix(prefix_options)}#{collection_name}/#{id}.#{format.extension}#{query_string(query_options)}"
  625
+        "#{prefix(prefix_options)}#{collection_name}/#{URI.escape id.to_s}.#{format.extension}#{query_string(query_options)}"
626 626
       end
627 627
 
628 628
       # Gets the new element path for REST resources.
1  activeresource/test/cases/base_test.rb
@@ -563,6 +563,7 @@ def test_custom_element_path
563 563
     assert_equal '/people/1/addresses/1.xml', StreetAddress.element_path(1, :person_id => 1)
564 564
     assert_equal '/people/1/addresses/1.xml', StreetAddress.element_path(1, 'person_id' => 1)
565 565
     assert_equal '/people/Greg/addresses/1.xml', StreetAddress.element_path(1, 'person_id' => 'Greg')
  566
+    assert_equal '/people/ann%20mary/addresses/ann%20mary.xml', StreetAddress.element_path(:'ann mary', 'person_id' => 'ann mary')
566 567
   end
567 568
 
568 569
   def test_module_element_path

0 notes on commit 0e969bd

Please sign in to comment.
Something went wrong with that request. Please try again.