Browse files

Duplicate possible frozen string from route

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...
1 parent 4e32722 commit c4106d0c08954b0761726e0015ec601b7bc7ea4b @pixeltrix pixeltrix committed Jan 21, 2013
Showing with 12 additions and 2 deletions.
  1. +3 −2 actionpack/lib/action_dispatch/routing/mapper.rb
  2. +9 −0 actionpack/test/dispatch/routing_test.rb
View
5 actionpack/lib/action_dispatch/routing/mapper.rb
@@ -1403,9 +1403,10 @@ def decomposed_match(path, options) # :nodoc:
def add_route(action, options) # :nodoc:
path = path_for_action(action, options.delete(:path))
+ action = action.to_s.dup
- if action.to_s =~ /^[\w\/]+$/
- options[:action] ||= action unless action.to_s.include?("/")
+ if action =~ /^[\w\/]+$/
+ options[:action] ||= action unless action.include?("/")
else
action = nil
end
View
9 actionpack/test/dispatch/routing_test.rb
@@ -2678,6 +2678,15 @@ def test_shallow_custom_param
assert_equal '0c0c0b68-d24b-11e1-a861-001ff3fffe6f', @request.params[:download]
end
+ def test_action_from_path_is_not_frozen
+ draw do
+ get 'search' => 'search'
+ end
+
+ get '/search'
+ assert !@request.params[:action].frozen?
+ end
+
private
def draw(&block)

0 comments on commit c4106d0

Please sign in to comment.