]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
gh-152212: Reject a POSIX TZ footer with a missing std offset in pure-Python `zoneinf...
authortonghuaroot (童话) <tonghuaroot@gmail.com>
Sat, 27 Jun 2026 09:16:43 +0000 (17:16 +0800)
committerGitHub <noreply@github.com>
Sat, 27 Jun 2026 09:16:43 +0000 (10:16 +0100)
Lib/test/test_zoneinfo/test_zoneinfo.py
Lib/zoneinfo/_zoneinfo.py
Misc/NEWS.d/next/Library/2026-06-25-12-00-00.gh-issue-152212.Zk7Qm2.rst [new file with mode: 0644]

index d4d57b8f727584f3372b6162a08ef5f5d05f3993..cf3f82db75b0b60e9edc0494034b5982db1b499d 100644 (file)
@@ -1142,6 +1142,11 @@ class TZStrTest(ZoneInfoTestBase):
     def test_invalid_tzstr(self):
         invalid_tzstrs = [
             "PST8PDT",  # DST but no transition specified
+            # gh-152212: the std offset is required (POSIX TZ grammar)
+            "AAA",
+            "A",
+            "AA",
+            "B",
             "+11",  # Unquoted alphanumeric
             "GMT,M3.2.0/2,M11.1.0/3",  # Transition rule but no DST
             "GMT0+11,M3.2.0/2,M11.1.0/3",  # Unquoted alphanumeric in DST
index 3903d57d55417e3d260d4641d0156dc025868236..52832f600c304487808b5d5c1d4d23ab6d5c7ddb 100644 (file)
@@ -672,7 +672,8 @@ def _parse_tz_str(tz_str):
         except ValueError as e:
             raise ValueError(f"Invalid STD offset in {tz_str}") from e
     else:
-        std_offset = 0
+        # The STD offset is required
+        raise ValueError(f"Invalid STD offset in {tz_str}")
 
     if dst_abbr is not None:
         if dst_offset := m.group("dstoff"):
diff --git a/Misc/NEWS.d/next/Library/2026-06-25-12-00-00.gh-issue-152212.Zk7Qm2.rst b/Misc/NEWS.d/next/Library/2026-06-25-12-00-00.gh-issue-152212.Zk7Qm2.rst
new file mode 100644 (file)
index 0000000..2b1d272
--- /dev/null
@@ -0,0 +1,3 @@
+Fix the pure-Python :mod:`zoneinfo` parser accepting a POSIX TZ string with a
+``std`` abbreviation but no offset. This is invalid per POSIX and now
+raises :exc:`ValueError`, matching the C accelerator. Patch by tonghuaroot.