From 816d67b104f9ea59cd0ffaccbcc250b66b7905d0 Mon Sep 17 00:00:00 2001 From: Jamis Buck Date: Wed, 7 Jun 2006 16:27:14 +0000 Subject: Make sure passed routing options are not mutated by routing code. (closes #5314) git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@4444 5ecf4fe2-1ee6-0310-87b1-e25e094e27de --- actionpack/CHANGELOG | 2 ++ actionpack/lib/action_controller/routing.rb | 9 +++++---- actionpack/test/controller/routing_test.rb | 24 +++++++++++++++++++++--- 3 files changed, 28 insertions(+), 7 deletions(-) diff --git a/actionpack/CHANGELOG b/actionpack/CHANGELOG index 33d3342a47..079bddffd7 100644 --- a/actionpack/CHANGELOG +++ b/actionpack/CHANGELOG @@ -1,5 +1,7 @@ *SVN* +* Make sure passed routing options are not mutated by routing code. #5314 [Blair Zajac] + * Make sure changing the controller from foo/bar to bing/bang does not change relative to foo. [Jamis Buck] * Escape the path before routing recognition. #3671 diff --git a/actionpack/lib/action_controller/routing.rb b/actionpack/lib/action_controller/routing.rb index 14921c3ac0..8638a1afb2 100644 --- a/actionpack/lib/action_controller/routing.rb +++ b/actionpack/lib/action_controller/routing.rb @@ -670,9 +670,10 @@ module ActionController # segments are passed alongside in order to distinguish between default values # and requirements. def divide_route_options(segments, options) - requirements = options.delete(:requirements) || {} - defaults = options.delete(:defaults) || {} - conditions = options.delete(:conditions) || {} + options = options.dup + requirements = (options.delete(:requirements) || {}).dup + defaults = (options.delete(:defaults) || {}).dup + conditions = (options.delete(:conditions) || {}).dup path_keys = segments.collect { |segment| segment.key if segment.respond_to?(:key) }.compact options.each do |key, value| @@ -1088,4 +1089,4 @@ module ActionController Routes = RouteSet.new end -end \ No newline at end of file +end diff --git a/actionpack/test/controller/routing_test.rb b/actionpack/test/controller/routing_test.rb index 44e986e3d5..8838ba841e 100644 --- a/actionpack/test/controller/routing_test.rb +++ b/actionpack/test/controller/routing_test.rb @@ -863,11 +863,29 @@ class RouteTest < Test::Unit::TestCase end class RouteBuilderTest < Test::Unit::TestCase - + def builder - @bulider ||= ROUTING::RouteBuilder.new + @builder ||= ROUTING::RouteBuilder.new end - + + def build(path, options) + builder.build(path, options) + end + + def test_options_should_not_be_modified + requirements1 = { :id => /\w+/, :controller => /(?:[a-z](?:-?[a-z]+)*)/ } + requirements2 = requirements1.dup + + assert_equal requirements1, requirements2 + + with_options(:controller => 'folder', + :requirements => requirements2) do |m| + m.build 'folders/new', :action => 'new' + end + + assert_equal requirements1, requirements2 + end + def test_segment_for_static segment, rest = builder.segment_for 'ulysses' assert_equal '', rest -- cgit v1.2.3