diff --git a/Lib/test/test_zoneinfo/test_zoneinfo.py b/Lib/test/test_zoneinfo/test_zoneinfo.py index fff6c0d865b441..6f6e2d4e700dc3 100644 --- a/Lib/test/test_zoneinfo/test_zoneinfo.py +++ b/Lib/test/test_zoneinfo/test_zoneinfo.py @@ -237,6 +237,7 @@ def test_bad_keys_paths(self): "America/../America/Los_Angeles", # Not normalized "America/./Los_Angeles", "", + b"", ] for bad_key in bad_keys: diff --git a/Lib/zoneinfo/_tzpath.py b/Lib/zoneinfo/_tzpath.py index 990a5c8b6a9372..7a9d15a41acbdb 100644 --- a/Lib/zoneinfo/_tzpath.py +++ b/Lib/zoneinfo/_tzpath.py @@ -83,10 +83,14 @@ def find_tzfile(key): def _validate_tzfile_path(path, _base=_TEST_PATH): - if not path: + if isinstance(path, str) and path == "": raise ValueError( "ZoneInfo key must not be an empty string" ) + elif isinstance(path, bytes) and path == b"": + raise ValueError( + "ZoneInfo key must not be an empty bytes object" + ) if os.path.isabs(path): raise ValueError( diff --git a/Misc/NEWS.d/next/Library/2025-04-16-11-58-20.gh-issue-114713.asdj1k.rst b/Misc/NEWS.d/next/Library/2025-04-16-11-58-20.gh-issue-114713.asdj1k.rst new file mode 100644 index 00000000000000..22bb639f90cbe9 --- /dev/null +++ b/Misc/NEWS.d/next/Library/2025-04-16-11-58-20.gh-issue-114713.asdj1k.rst @@ -0,0 +1,2 @@ +Handle case of an empty bytes object passed to :class:`zoneinfo.ZoneInfo`. +