Permalink
Browse files

Make sure passed routing options are not mutated by routing code. (cl…

…oses #5314)

git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@4444 5ecf4fe2-1ee6-0310-87b1-e25e094e27de
  • Loading branch information...
jamis committed Jun 7, 2006
1 parent ae7029d commit 816d67b104f9ea59cd0ffaccbcc250b66b7905d0
Showing with 28 additions and 7 deletions.
  1. +2 −0 actionpack/CHANGELOG
  2. +5 −4 actionpack/lib/action_controller/routing.rb
  3. +21 −3 actionpack/test/controller/routing_test.rb
View
@@ -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
@@ -670,9 +670,10 @@ def segment_for(string)
# 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 @@ def extract_request_environment(request)
Routes = RouteSet.new
end
-end
+end
@@ -863,11 +863,29 @@ def test_escape_spaces_build_query_string_selected_keys
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

0 comments on commit 816d67b

Please sign in to comment.