From 22f00f8d3d4850d774f7ad62553dccad762c8994 Mon Sep 17 00:00:00 2001 From: Leigh Caplan Date: Tue, 22 Jun 2010 19:14:50 -0700 Subject: [PATCH] Prevent bogus time zones from storing nil keys in ActiveSupport::TimeZone.zones_map --- .../lib/active_support/values/time_zone.rb | 6 +++++- activesupport/test/time_zone_test.rb | 5 +++++ 2 files changed, 10 insertions(+), 1 deletions(-) diff --git a/activesupport/lib/active_support/values/time_zone.rb b/activesupport/lib/active_support/values/time_zone.rb index 52f0f0f..a787204 100644 --- a/activesupport/lib/active_support/values/time_zone.rb +++ b/activesupport/lib/active_support/values/time_zone.rb @@ -387,7 +387,11 @@ module ActiveSupport def [](arg) case arg when String - zones_map[arg] ||= lookup(arg) + return zones_map[arg] if zones_map[arg] + + if zone = lookup(arg) + zones_map[arg] = zone + end when Numeric, ActiveSupport::Duration arg *= 3600 if arg.abs <= 13 all.find { |z| z.utc_offset == arg.to_i } diff --git a/activesupport/test/time_zone_test.rb b/activesupport/test/time_zone_test.rb index 41d203d..ce902f4 100644 --- a/activesupport/test/time_zone_test.rb +++ b/activesupport/test/time_zone_test.rb @@ -269,6 +269,11 @@ class TimeZoneTest < Test::Unit::TestCase assert ActiveSupport::TimeZone.us_zones.include?(ActiveSupport::TimeZone["Hawaii"]) assert !ActiveSupport::TimeZone.us_zones.include?(ActiveSupport::TimeZone["Kuala Lumpur"]) end + + def test_unknown_zones_dont_store_mapping_keys + ActiveSupport::TimeZone["bogus"] + assert !ActiveSupport::TimeZone.zones_map.key?("bogus") + end protected def with_env_tz(new_tz = 'US/Eastern') -- 1.6.5.3