diff --git a/lib/tzinfo/zoneinfo_data_source.rb b/lib/tzinfo/zoneinfo_data_source.rb index 3959090f..6b250a13 100644 --- a/lib/tzinfo/zoneinfo_data_source.rb +++ b/lib/tzinfo/zoneinfo_data_source.rb @@ -87,6 +87,30 @@ class ZoneinfoDataSource < DataSource # The default value of ZoneinfoDataSource.alternate_iso3166_tab_search_path. DEFAULT_ALTERNATE_ISO3166_TAB_SEARCH_PATH = ['/usr/share/misc/iso3166.tab', '/usr/share/misc/iso3166'].freeze + # File and directories in the top level zoneinfo directory that will be + # excluded from the list of available time zones: + # + # - +VERSION is included on Mac OS X. + # - leapseconds is a list of leap seconds. + # - localtime is the current local timezone (may be a link). + # - posix, posixrules and right are directories containing other versions + # of the zoneinfo files. + # - SECURITY is included in the Arch Linux tzdata package. + # - src is a directory containing the tzdata source included on Solaris. + # - timeconfig is a symlink included on Slackware. + EXCLUDED_FILENAMES = [ + '+VERSION', + 'leapseconds', + 'localtime', + 'posix', + 'posixrules', + 'right', + 'SECURITY', + 'src', + 'timeconfig' + ].freeze + private_constant :EXCLUDED_FILENAMES + # Paths to be checked to find the system zoneinfo directory. @@search_path = DEFAULT_SEARCH_PATH.dup @@ -352,16 +376,8 @@ def find_zoneinfo_dir # identifiers. def load_timezone_index index = [] - - # Ignoring particular files: - # +VERSION is included on Mac OS X. - # leapseconds is a list of leap seconds. - # localtime is the current local timezone (may be a link). - # posix, posixrules and right are directories containing other versions of the zoneinfo files. - # src is a directory containing the tzdata source included on Solaris. - # timeconfig is a symlink included on Slackware. - - enum_timezones(nil, ['+VERSION', 'leapseconds', 'localtime', 'posix', 'posixrules', 'right', 'src', 'timeconfig']) do |identifier| + + enum_timezones(nil, EXCLUDED_FILENAMES) do |identifier| index << identifier end diff --git a/test/tc_zoneinfo_data_source.rb b/test/tc_zoneinfo_data_source.rb index fe517cbb..4fd0d13b 100644 --- a/test/tc_zoneinfo_data_source.rb +++ b/test/tc_zoneinfo_data_source.rb @@ -818,6 +818,25 @@ def test_timezone_identifiers_ignored_src_directory end end + def test_timezone_identifiers_ignored_security_file + # The Arch linux tzdata package includes a file named SECURITY giving + # instructions for reporting security-related bugs. + + Dir.mktmpdir('tzinfo_test') do |dir| + FileUtils.touch(File.join(dir, 'zone.tab')) + FileUtils.touch(File.join(dir, 'iso3166.tab')) + FileUtils.cp(File.join(@data_source.zoneinfo_dir, 'EST'), File.join(dir, 'EST')) + + File.open(File.join(dir, 'SECURITY'), 'w') do |f| + f.binmode + f.write("Please report any sensitive security-related bugs...\n") + end + + data_source = ZoneinfoDataSource.new(dir) + assert_equal(['EST'], data_source.timezone_identifiers) + end + end + def test_load_country_info info = @data_source.load_country_info('GB') assert_equal('GB', info.code)