aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--actionpack/CHANGELOG2
-rw-r--r--actionpack/lib/action_controller/polymorphic_routes.rb4
-rw-r--r--actionpack/test/controller/polymorphic_routes_test.rb7
3 files changed, 13 insertions, 0 deletions
diff --git a/actionpack/CHANGELOG b/actionpack/CHANGELOG
index 9772ca847e..b71f3a51f3 100644
--- a/actionpack/CHANGELOG
+++ b/actionpack/CHANGELOG
@@ -1,5 +1,7 @@
*SVN*
+* Fixed that polymorphic routes would modify the input array #11363 [thomas.lee]
+
* Added :format option to NumberHelper#number_to_currency to enable better localization support #11149 [lylo]
* Fixed that TextHelper#excerpt would include one character too many #11268 [Irfy]
diff --git a/actionpack/lib/action_controller/polymorphic_routes.rb b/actionpack/lib/action_controller/polymorphic_routes.rb
index ec883af26d..f043d89dae 100644
--- a/actionpack/lib/action_controller/polymorphic_routes.rb
+++ b/actionpack/lib/action_controller/polymorphic_routes.rb
@@ -68,6 +68,10 @@ module ActionController
# polymorphic_url(record) #-> comments_url()
#
def polymorphic_url(record_or_hash_or_array, options = {})
+ if record_or_hash_or_array.kind_of?(Array)
+ record_or_hash_or_array = record_or_hash_or_array.dup
+ end
+
record = extract_record(record_or_hash_or_array)
format = (options[:action].to_s == "formatted" and record_or_hash_or_array.pop)
namespace = extract_namespace(record_or_hash_or_array)
diff --git a/actionpack/test/controller/polymorphic_routes_test.rb b/actionpack/test/controller/polymorphic_routes_test.rb
index 90c149a830..0d349a360c 100644
--- a/actionpack/test/controller/polymorphic_routes_test.rb
+++ b/actionpack/test/controller/polymorphic_routes_test.rb
@@ -125,5 +125,12 @@ uses_mocha 'polymorphic URL helpers' do
polymorphic_path(@article, :action => :new)
end
+ def test_polymorphic_path_does_not_modify_arguments
+ expects(:admin_article_responses_url).with(@article)
+ path = [:admin, @article, @response]
+ assert_no_difference 'path.size' do
+ polymorphic_url(path)
+ end
+ end
end
end