Skip to content
Browse files

Merge pull request #2497 from akaspick/url_for_fix

When calling url_for with a hash, additional (likely unwanted) values (such as :host) would be returned in the hash
  • Loading branch information...
2 parents e6fdfd0 + 61579b7 commit d1f1b04386cb50521128b3e44630f704bb738194 @spastorino spastorino committed Aug 11, 2011
Showing with 13 additions and 1 deletion.
  1. +1 −1 actionpack/lib/action_dispatch/routing/url_for.rb
  2. +12 −0 actionpack/test/dispatch/routing_test.rb
View
2 actionpack/lib/action_dispatch/routing/url_for.rb
@@ -140,7 +140,7 @@ def url_for(options = nil)
when String
options
when nil, Hash
- _routes.url_for((options || {}).reverse_merge!(url_options).symbolize_keys)
+ _routes.url_for((options.dup || {}).reverse_merge!(url_options).symbolize_keys)
else
polymorphic_url(options)
end
View
12 actionpack/test/dispatch/routing_test.rb
@@ -851,6 +851,18 @@ def test_local
end
end
+ # tests the use of dup in url_for
+ def test_url_for_with_no_side_effects
+ # without dup, additional (and possibly unwanted) values will be present in the options (eg. :host)
+ original_options = {:controller => 'projects', :action => 'status'}
+ options = original_options.dup
+
+ url_for options
+
+ # verify that the options passed in have not changed from the original ones
+ assert_equal original_options, options
+ end
+
def test_projects_status
with_test_routes do
assert_equal '/projects/status', url_for(:controller => 'projects', :action => 'status', :only_path => true)

0 comments on commit d1f1b04

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