diff options
-rw-r--r-- | actionpack/CHANGELOG.md | 8 | ||||
-rw-r--r-- | actionpack/lib/action_view/helpers/form_options_helper.rb | 2 | ||||
-rw-r--r-- | actionpack/test/template/form_options_helper_test.rb | 7 |
3 files changed, 16 insertions, 1 deletions
diff --git a/actionpack/CHANGELOG.md b/actionpack/CHANGELOG.md index 6047c83167..9b8b175450 100644 --- a/actionpack/CHANGELOG.md +++ b/actionpack/CHANGELOG.md @@ -1,5 +1,13 @@ ## Rails 4.0.0 (unreleased) ## +* Fix `time_zone_options_for_select` to call `dup` on the returned TimeZone array. + + Previously if you supplied :priority_zones options to `time_zone_options_for_select` + the memoized ActiveSupport::TimeZone.all array would be mutated. Calling + `dup` prevents mutation of the main TimeZones array. + + *Brian McManus* + * Remove support for parsing YAML parameters from request. *Aaron Patterson* diff --git a/actionpack/lib/action_view/helpers/form_options_helper.rb b/actionpack/lib/action_view/helpers/form_options_helper.rb index 8b3a37a853..49473dd129 100644 --- a/actionpack/lib/action_view/helpers/form_options_helper.rb +++ b/actionpack/lib/action_view/helpers/form_options_helper.rb @@ -560,7 +560,7 @@ module ActionView def time_zone_options_for_select(selected = nil, priority_zones = nil, model = ::ActiveSupport::TimeZone) zone_options = "".html_safe - zones = model.all + zones = model.all.dup convert_zones = lambda { |list| list.map { |z| [ z.to_s, z.name ] } } if priority_zones diff --git a/actionpack/test/template/form_options_helper_test.rb b/actionpack/test/template/form_options_helper_test.rb index c5efed3195..757b05dbc1 100644 --- a/actionpack/test/template/form_options_helper_test.rb +++ b/actionpack/test/template/form_options_helper_test.rb @@ -416,6 +416,13 @@ class FormOptionsHelperTest < ActionView::TestCase "<option value=\"D\">D</option>", opts end + + def test_time_zone_options_with_priority_zones_does_not_mutate_time_zones + original_zones = ActiveSupport::TimeZone.all.dup + zones = [ ActiveSupport::TimeZone.new( "B" ), ActiveSupport::TimeZone.new( "E" ) ] + opts = time_zone_options_for_select( nil, zones ) + assert_equal original_zones, ActiveSupport::TimeZone.all + end def test_time_zone_options_returns_html_safe_string assert time_zone_options_for_select.html_safe? |