Skip to content

Commit

Permalink
Duplicate possible frozen string from route
Browse files Browse the repository at this point in the history
Ruby 1.9 freezes Hash string keys by default so where a route is
defined like this:

get 'search' => 'search'

then the Mapper will derive the action from the key. This blows up
later when the action is added to the parameters hash and the
encoding is forced.

Closes #3429
  • Loading branch information
pixeltrix committed Jan 21, 2013
1 parent a3aca81 commit 4317596
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 2 deletions.
5 changes: 3 additions & 2 deletions actionpack/lib/action_dispatch/routing/mapper.rb
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -1288,9 +1288,10 @@ def decomposed_match(path, options) # :nodoc:


def add_route(action, options) # :nodoc: def add_route(action, options) # :nodoc:
path = path_for_action(action, options.delete(:path)) path = path_for_action(action, options.delete(:path))
action = action.to_s.dup


if action.to_s =~ /^[\w\/]+$/ if action =~ /^[\w\/]+$/
options[:action] ||= action unless action.to_s.include?("/") options[:action] ||= action unless action.include?("/")
else else
action = nil action = nil
end end
Expand Down
7 changes: 7 additions & 0 deletions actionpack/test/dispatch/routing_test.rb
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -515,6 +515,8 @@ def self.call(params, request)
match '/sculptors', :to => 'italians#sculptors' match '/sculptors', :to => 'italians#sculptors'
match '/painters/:painter', :to => 'italians#painters', :constraints => {:painter => /michelangelo/} match '/painters/:painter', :to => 'italians#painters', :constraints => {:painter => /michelangelo/}
end end

get 'search' => 'search'
end end
end end


Expand Down Expand Up @@ -2477,6 +2479,11 @@ def test_root_in_deeply_nested_scope
assert_equal "/posts/1/admin", post_admin_root_path(:post_id => '1') assert_equal "/posts/1/admin", post_admin_root_path(:post_id => '1')
end end


def test_action_from_path_is_not_frozen
get '/search'
assert !@request.params[:action].frozen?
end

private private
def with_test_routes def with_test_routes
yield yield
Expand Down

0 comments on commit 4317596

Please sign in to comment.