Skip to content

Commit 6a4766e

Browse files
committed
Merge pull request #133.
2 parents 5d53b59 + 83450a1 commit 6a4766e

2 files changed

Lines changed: 40 additions & 9 deletions

File tree

lib/tzinfo/data_sources/zoneinfo_data_source.rb

Lines changed: 21 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,26 @@ class ZoneinfoDataSource < DataSource
7878
DEFAULT_ALTERNATE_ISO3166_TAB_SEARCH_PATH = ['/usr/share/misc/iso3166.tab', '/usr/share/misc/iso3166'].freeze
7979
private_constant :DEFAULT_ALTERNATE_ISO3166_TAB_SEARCH_PATH
8080

81+
# Ignoring particular files:
82+
# +VERSION is included on Mac OS X.
83+
# leapseconds is a list of leap seconds.
84+
# localtime is the current local timezone (may be a link).
85+
# posix, posixrules and right are directories containing other versions of
86+
# the zoneinfo files.
87+
# SECURITY is included in Arch tzdata package.
88+
# src is a directory containing the tzdata source included on Solaris.
89+
# timeconfig is a symlink included on Slackware.
90+
EXCLUDED_FILENAMES = ['+VERSION',
91+
'leapseconds',
92+
'localtime',
93+
'posix',
94+
'posixrules',
95+
'right',
96+
'SECURITY',
97+
'src',
98+
'timeconfig']
99+
private_constant :EXCLUDED_FILENAMES
100+
81101
# Paths to be checked to find the system zoneinfo directory.
82102
#
83103
# @private
@@ -394,15 +414,7 @@ def find_zoneinfo_dir
394414
def load_timezone_identifiers
395415
index = []
396416

397-
# Ignoring particular files:
398-
# +VERSION is included on Mac OS X.
399-
# leapseconds is a list of leap seconds.
400-
# localtime is the current local timezone (may be a link).
401-
# posix, posixrules and right are directories containing other versions of the zoneinfo files.
402-
# src is a directory containing the tzdata source included on Solaris.
403-
# timeconfig is a symlink included on Slackware.
404-
405-
enum_timezones([], ['+VERSION', 'leapseconds', 'localtime', 'posix', 'posixrules', 'right', 'src', 'timeconfig']) do |identifier|
417+
enum_timezones([], EXCLUDED_FILENAMES) do |identifier|
406418
index << identifier.join('/').freeze
407419
end
408420

test/data_sources/tc_zoneinfo_data_source.rb

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1082,6 +1082,25 @@ def test_timezone_identifiers_ignored_src_directory
10821082
end
10831083
end
10841084

1085+
def test_timezone_identifiers_ignored_security_file
1086+
# Arch tzdata package includes a file named SECURITY giving instructions
1087+
# to report any security-related bug.
1088+
1089+
Dir.mktmpdir('tzinfo_test') do |dir|
1090+
FileUtils.touch(File.join(dir, 'zone.tab'))
1091+
FileUtils.touch(File.join(dir, 'iso3166.tab'))
1092+
FileUtils.cp(File.join(@data_source.zoneinfo_dir, 'EST'), File.join(dir, 'EST'))
1093+
1094+
File.open(File.join(dir, 'SECURITY'), 'w') do |f|
1095+
f.binmode
1096+
f.write("2013a\n")
1097+
end
1098+
1099+
data_source = ZoneinfoDataSource.new(dir)
1100+
assert_equal(['EST'], data_source.timezone_identifiers)
1101+
end
1102+
end
1103+
10851104
def test_load_country_info
10861105
info = @data_source.send(:load_country_info, 'GB')
10871106
assert_equal('GB', info.code)

0 commit comments

Comments
 (0)