aboutsummaryrefslogtreecommitdiffstats
path: root/activeresource
diff options
context:
space:
mode:
authorJosef Reidinger <jreidinger@suse.cz>2010-07-22 08:42:02 +0200
committerJosé Valim <jose.valim@gmail.com>2010-07-26 16:59:47 +0200
commit0e969bdaf8ff2e3384350687aa0b583f94d6dfbc (patch)
tree796a391200d0138ed0a3e135b04b272739fb1d0d /activeresource
parent78c8242d2f92bccc4caedc235b8cfbcfcb3650cf (diff)
downloadrails-0e969bdaf8ff2e3384350687aa0b583f94d6dfbc.tar.gz
rails-0e969bdaf8ff2e3384350687aa0b583f94d6dfbc.tar.bz2
rails-0e969bdaf8ff2e3384350687aa0b583f94d6dfbc.zip
fix escaping id and parameters in path [#5137 state:resolved]
Signed-off-by: José Valim <jose.valim@gmail.com>
Diffstat (limited to 'activeresource')
-rw-r--r--activeresource/lib/active_resource/base.rb4
-rw-r--r--activeresource/test/cases/base_test.rb1
2 files changed, 3 insertions, 2 deletions
diff --git a/activeresource/lib/active_resource/base.rb b/activeresource/lib/active_resource/base.rb
index 1557e090e1..72ad2f5872 100644
--- a/activeresource/lib/active_resource/base.rb
+++ b/activeresource/lib/active_resource/base.rb
@@ -577,7 +577,7 @@ module ActiveResource
# Default value is <tt>site.path</tt>.
def prefix=(value = '/')
# Replace :placeholders with '#{embedded options[:lookups]}'
- prefix_call = value.gsub(/:\w+/) { |key| "\#{options[#{key}]}" }
+ prefix_call = value.gsub(/:\w+/) { |key| "\#{URI.escape options[#{key}].to_s}" }
# Clear prefix parameters in case they have been cached
@prefix_parameters = nil
@@ -622,7 +622,7 @@ module ActiveResource
#
def element_path(id, prefix_options = {}, query_options = nil)
prefix_options, query_options = split_options(prefix_options) if query_options.nil?
- "#{prefix(prefix_options)}#{collection_name}/#{id}.#{format.extension}#{query_string(query_options)}"
+ "#{prefix(prefix_options)}#{collection_name}/#{URI.escape id.to_s}.#{format.extension}#{query_string(query_options)}"
end
# Gets the new element path for REST resources.
diff --git a/activeresource/test/cases/base_test.rb b/activeresource/test/cases/base_test.rb
index a176c037d5..91b375681b 100644
--- a/activeresource/test/cases/base_test.rb
+++ b/activeresource/test/cases/base_test.rb
@@ -563,6 +563,7 @@ class BaseTest < Test::Unit::TestCase
assert_equal '/people/1/addresses/1.xml', StreetAddress.element_path(1, :person_id => 1)
assert_equal '/people/1/addresses/1.xml', StreetAddress.element_path(1, 'person_id' => 1)
assert_equal '/people/Greg/addresses/1.xml', StreetAddress.element_path(1, 'person_id' => 'Greg')
+ assert_equal '/people/ann%20mary/addresses/ann%20mary.xml', StreetAddress.element_path(:'ann mary', 'person_id' => 'ann mary')
end
def test_module_element_path