From 884df116d79b05d9342e05e50484d61c684ecb8b Mon Sep 17 00:00:00 2001 From: Bogdan Romanyuk <65823030+wrongnull@users.noreply.github.com> Date: Tue, 15 Apr 2025 18:41:52 +0000 Subject: gh-114713: Handle case of an empty string passed to `zoneinfo.ZoneInfo` (#114731) Co-authored-by: Stan Ulbrych <89152624+StanFromIreland@users.noreply.github.com> Co-authored-by: Kirill Podoprigora --- Lib/test/test_zoneinfo/test_zoneinfo.py | 1 + Lib/zoneinfo/_tzpath.py | 5 +++++ .../next/Library/2025-03-09-01-09-12.gh-issue-114713.lkq9vZ.rst | 1 + 3 files changed, 7 insertions(+) create mode 100644 Misc/NEWS.d/next/Library/2025-03-09-01-09-12.gh-issue-114713.lkq9vZ.rst diff --git a/Lib/test/test_zoneinfo/test_zoneinfo.py b/Lib/test/test_zoneinfo/test_zoneinfo.py index 102a487..fff6c0d 100644 --- a/Lib/test/test_zoneinfo/test_zoneinfo.py +++ b/Lib/test/test_zoneinfo/test_zoneinfo.py @@ -236,6 +236,7 @@ class ZoneInfoTest(TzPathUserMixin, ZoneInfoTestBase): "../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 5db17be..990a5c8 100644 --- a/Lib/zoneinfo/_tzpath.py +++ b/Lib/zoneinfo/_tzpath.py @@ -83,6 +83,11 @@ _TEST_PATH = os.path.normpath(os.path.join("_", "_"))[:-1] 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 0000000..d30975a --- /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`. -- cgit v0.12