Skip to content

Commit

Permalink
Exclude Arch Linux's SECURITY file from the time zone index.
Browse files Browse the repository at this point in the history
Resolves #134 for version 1.2.
  • Loading branch information
philr committed Jul 17, 2022
1 parent 17fc9e1 commit 5e9f990
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 10 deletions.
36 changes: 26 additions & 10 deletions lib/tzinfo/zoneinfo_data_source.rb
Expand Up @@ -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

Expand Down Expand Up @@ -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

Expand Down
19 changes: 19 additions & 0 deletions test/tc_zoneinfo_data_source.rb
Expand Up @@ -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)
Expand Down

0 comments on commit 5e9f990

Please sign in to comment.