diff --git a/Lib/test/test_zoneinfo/test_zoneinfo.py b/Lib/test/test_zoneinfo/test_zoneinfo.py index 8414721555731e..8c6ce991d30b40 100644 --- a/Lib/test/test_zoneinfo/test_zoneinfo.py +++ b/Lib/test/test_zoneinfo/test_zoneinfo.py @@ -235,6 +235,7 @@ def test_bad_keys_paths(self): "../zoneinfo/America/Los_Angeles", # Traverses above TZPATH "America/../America/Los_Angeles", # Not normalized "America/./Los_Angeles", + "", ] for bad_key in bad_keys: diff --git a/Lib/zoneinfo/_tzpath.py b/Lib/zoneinfo/_tzpath.py index 5db17bea045d8c..990a5c8b6a9372 100644 --- a/Lib/zoneinfo/_tzpath.py +++ b/Lib/zoneinfo/_tzpath.py @@ -83,6 +83,11 @@ def find_tzfile(key): def _validate_tzfile_path(path, _base=_TEST_PATH): + if not path: + raise ValueError( + "ZoneInfo key must not be an empty string" + ) + if os.path.isabs(path): raise ValueError( f"ZoneInfo keys may not be absolute paths, got: {path}" diff --git a/Misc/NEWS.d/next/Library/2025-03-09-01-09-12.gh-issue-114713.lkq9vZ.rst b/Misc/NEWS.d/next/Library/2025-03-09-01-09-12.gh-issue-114713.lkq9vZ.rst new file mode 100644 index 00000000000000..d30975a8a5115b --- /dev/null +++ b/Misc/NEWS.d/next/Library/2025-03-09-01-09-12.gh-issue-114713.lkq9vZ.rst @@ -0,0 +1 @@ +Handle case of an empty string passed to :class:`zoneinfo.ZoneInfo`.