Skip to content

Commit 5e9f990

Browse files
committed
Exclude Arch Linux's SECURITY file from the time zone index.
Resolves #134 for version 1.2.
1 parent 17fc9e1 commit 5e9f990

2 files changed

Lines changed: 45 additions & 10 deletions

File tree

lib/tzinfo/zoneinfo_data_source.rb

Lines changed: 26 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,30 @@ class ZoneinfoDataSource < DataSource
8787
# The default value of ZoneinfoDataSource.alternate_iso3166_tab_search_path.
8888
DEFAULT_ALTERNATE_ISO3166_TAB_SEARCH_PATH = ['/usr/share/misc/iso3166.tab', '/usr/share/misc/iso3166'].freeze
8989

90+
# File and directories in the top level zoneinfo directory that will be
91+
# excluded from the list of available time zones:
92+
#
93+
# - +VERSION is included on Mac OS X.
94+
# - leapseconds is a list of leap seconds.
95+
# - localtime is the current local timezone (may be a link).
96+
# - posix, posixrules and right are directories containing other versions
97+
# of the zoneinfo files.
98+
# - SECURITY is included in the Arch Linux tzdata package.
99+
# - src is a directory containing the tzdata source included on Solaris.
100+
# - timeconfig is a symlink included on Slackware.
101+
EXCLUDED_FILENAMES = [
102+
'+VERSION',
103+
'leapseconds',
104+
'localtime',
105+
'posix',
106+
'posixrules',
107+
'right',
108+
'SECURITY',
109+
'src',
110+
'timeconfig'
111+
].freeze
112+
private_constant :EXCLUDED_FILENAMES
113+
90114
# Paths to be checked to find the system zoneinfo directory.
91115
@@search_path = DEFAULT_SEARCH_PATH.dup
92116

@@ -352,16 +376,8 @@ def find_zoneinfo_dir
352376
# identifiers.
353377
def load_timezone_index
354378
index = []
355-
356-
# Ignoring particular files:
357-
# +VERSION is included on Mac OS X.
358-
# leapseconds is a list of leap seconds.
359-
# localtime is the current local timezone (may be a link).
360-
# posix, posixrules and right are directories containing other versions of the zoneinfo files.
361-
# src is a directory containing the tzdata source included on Solaris.
362-
# timeconfig is a symlink included on Slackware.
363-
364-
enum_timezones(nil, ['+VERSION', 'leapseconds', 'localtime', 'posix', 'posixrules', 'right', 'src', 'timeconfig']) do |identifier|
379+
380+
enum_timezones(nil, EXCLUDED_FILENAMES) do |identifier|
365381
index << identifier
366382
end
367383

test/tc_zoneinfo_data_source.rb

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -818,6 +818,25 @@ def test_timezone_identifiers_ignored_src_directory
818818
end
819819
end
820820

821+
def test_timezone_identifiers_ignored_security_file
822+
# The Arch linux tzdata package includes a file named SECURITY giving
823+
# instructions for reporting security-related bugs.
824+
825+
Dir.mktmpdir('tzinfo_test') do |dir|
826+
FileUtils.touch(File.join(dir, 'zone.tab'))
827+
FileUtils.touch(File.join(dir, 'iso3166.tab'))
828+
FileUtils.cp(File.join(@data_source.zoneinfo_dir, 'EST'), File.join(dir, 'EST'))
829+
830+
File.open(File.join(dir, 'SECURITY'), 'w') do |f|
831+
f.binmode
832+
f.write("Please report any sensitive security-related bugs...\n")
833+
end
834+
835+
data_source = ZoneinfoDataSource.new(dir)
836+
assert_equal(['EST'], data_source.timezone_identifiers)
837+
end
838+
end
839+
821840
def test_load_country_info
822841
info = @data_source.load_country_info('GB')
823842
assert_equal('GB', info.code)

0 commit comments

Comments
 (0)