Permalink
Browse files

prevent errors when passing a frozen string as a param to ActionContr…

…oller::TestCase#process

since ActionDispatch::Http::Parameters#encode_params will force encoding on all params strings (when using an encoding aware Ruby), dup all strings passed into process.  This prevents modification of params passed in and, more importantly, doesn't barf when a frozen string is passed
thanks and high fives to kinsteronline
  • Loading branch information...
1 parent 1cd5a08 commit 9f6cafd5fd43b551f30b28d276713791c5098b3c @misfo misfo committed with dhh Feb 8, 2011
Showing with 15 additions and 1 deletion.
  1. +3 −1 actionpack/lib/action_controller/test_case.rb
  2. +12 −0 actionpack/test/controller/test_test.rb
@@ -147,7 +147,9 @@ def assign_parameters(routes, controller_path, action, parameters = {})
if value.is_a? Fixnum
value = value.to_s
elsif value.is_a? Array
- value = Result.new(value)
+ value = Result.new(value.map { |v| v.is_a?(String) ? v.dup : v })
+ elsif value.is_a? String
+ value = value.dup
end
if extra_keys.include?(key.to_sym)
@@ -493,6 +493,18 @@ def test_params_passing
)
end
+ def test_params_passing_with_frozen_values
+ assert_nothing_raised do
+ get :test_params, :frozen => 'icy'.freeze, :frozens => ['icy'.freeze].freeze
+ end
+ parsed_params = eval(@response.body)
+ assert_equal(
+ {'controller' => 'test_test/test', 'action' => 'test_params',
+ 'frozen' => 'icy', 'frozens' => ['icy']},
+ parsed_params
+ )
+ end
+
def test_id_converted_to_string
get :test_params, :id => 20, :foo => Object.new
assert_kind_of String, @request.path_parameters['id']

0 comments on commit 9f6cafd

Please sign in to comment.