Skip to content

Commit

Permalink
Merge pull request #133.
Browse files Browse the repository at this point in the history
  • Loading branch information
philr committed Jul 17, 2022
2 parents 5d53b59 + 83450a1 commit 6a4766e
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 9 deletions.
30 changes: 21 additions & 9 deletions lib/tzinfo/data_sources/zoneinfo_data_source.rb
Expand Up @@ -78,6 +78,26 @@ class ZoneinfoDataSource < DataSource
DEFAULT_ALTERNATE_ISO3166_TAB_SEARCH_PATH = ['/usr/share/misc/iso3166.tab', '/usr/share/misc/iso3166'].freeze
private_constant :DEFAULT_ALTERNATE_ISO3166_TAB_SEARCH_PATH

# 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.
# SECURITY is included in Arch 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']
private_constant :EXCLUDED_FILENAMES

# Paths to be checked to find the system zoneinfo directory.
#
# @private
Expand Down Expand Up @@ -394,15 +414,7 @@ def find_zoneinfo_dir
def load_timezone_identifiers
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([], ['+VERSION', 'leapseconds', 'localtime', 'posix', 'posixrules', 'right', 'src', 'timeconfig']) do |identifier|
enum_timezones([], EXCLUDED_FILENAMES) do |identifier|
index << identifier.join('/').freeze
end

Expand Down
19 changes: 19 additions & 0 deletions test/data_sources/tc_zoneinfo_data_source.rb
Expand Up @@ -1082,6 +1082,25 @@ def test_timezone_identifiers_ignored_src_directory
end
end

def test_timezone_identifiers_ignored_security_file
# Arch tzdata package includes a file named SECURITY giving instructions
# to report any security-related bug.

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("2013a\n")
end

data_source = ZoneinfoDataSource.new(dir)
assert_equal(['EST'], data_source.timezone_identifiers)
end
end

def test_load_country_info
info = @data_source.send(:load_country_info, 'GB')
assert_equal('GB', info.code)
Expand Down

0 comments on commit 6a4766e

Please sign in to comment.