aboutsummaryrefslogtreecommitdiffstats
path: root/actionpack
diff options
context:
space:
mode:
authorJamis Buck <jamis@37signals.com>2006-06-07 16:27:14 +0000
committerJamis Buck <jamis@37signals.com>2006-06-07 16:27:14 +0000
commit816d67b104f9ea59cd0ffaccbcc250b66b7905d0 (patch)
tree42f998e62d9cc71635898c06d4bf4a37880d95e9 /actionpack
parentae7029ddd1fe11890479df119d0f5996c40c80de (diff)
downloadrails-816d67b104f9ea59cd0ffaccbcc250b66b7905d0.tar.gz
rails-816d67b104f9ea59cd0ffaccbcc250b66b7905d0.tar.bz2
rails-816d67b104f9ea59cd0ffaccbcc250b66b7905d0.zip
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
Diffstat (limited to 'actionpack')
-rw-r--r--actionpack/CHANGELOG2
-rw-r--r--actionpack/lib/action_controller/routing.rb9
-rw-r--r--actionpack/test/controller/routing_test.rb24
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