Skip to content

Commit

Permalink
Make sure passed routing options are not mutated by routing code. (cl…
Browse files Browse the repository at this point in the history
…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 816d67b
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 7 deletions.
2 changes: 2 additions & 0 deletions 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
Expand Down
9 changes: 5 additions & 4 deletions actionpack/lib/action_controller/routing.rb
Expand Up @@ -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|
Expand Down Expand Up @@ -1088,4 +1089,4 @@ def extract_request_environment(request)

Routes = RouteSet.new
end
end
end
24 changes: 21 additions & 3 deletions actionpack/test/controller/routing_test.rb
Expand Up @@ -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
Expand Down

0 comments on commit 816d67b

Please sign in to comment.