From 9f6cafd5fd43b551f30b28d276713791c5098b3c Mon Sep 17 00:00:00 2001 From: misfo Date: Tue, 8 Feb 2011 12:08:35 +0800 Subject: prevent errors when passing a frozen string as a param to ActionController::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 --- actionpack/lib/action_controller/test_case.rb | 4 +++- actionpack/test/controller/test_test.rb | 12 ++++++++++++ 2 files changed, 15 insertions(+), 1 deletion(-) (limited to 'actionpack') diff --git a/actionpack/lib/action_controller/test_case.rb b/actionpack/lib/action_controller/test_case.rb index bc4f8bb9ce..0085f542aa 100644 --- a/actionpack/lib/action_controller/test_case.rb +++ b/actionpack/lib/action_controller/test_case.rb @@ -147,7 +147,9 @@ module ActionController 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) diff --git a/actionpack/test/controller/test_test.rb b/actionpack/test/controller/test_test.rb index edda0d0a30..5896222a0a 100644 --- a/actionpack/test/controller/test_test.rb +++ b/actionpack/test/controller/test_test.rb @@ -493,6 +493,18 @@ XML ) 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'] -- cgit v1.2.3