Skip to content

Commit c89a533

Browse files
committed
gh-152246: Reject a POSIX TZ Mm.w.d rule with a non-period separator in pure-Python zoneinfo
1 parent ad38cf8 commit c89a533

3 files changed

Lines changed: 12 additions & 1 deletion

File tree

Lib/test/test_zoneinfo/test_zoneinfo.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1184,6 +1184,11 @@ def test_invalid_tzstr(self):
11841184
# Invalid weekday
11851185
"AAA4BBB,M1.1.7/2,M2.1.1/2",
11861186
"AAA4BBB,M1.1.1/2,M2.1.7/2",
1187+
# Invalid Mm.w.d separator (must be a literal '.')
1188+
"AAA4BBB,M3.2X0,M11.1.0",
1189+
"AAA4BBB,M3.2.0,M11.1X0",
1190+
"AAA4BBB,M3.2-0,M11.1.0/3",
1191+
"AAA4BBB,M3.2.0/2,M11.1:0",
11871192
# Invalid numeric offset
11881193
"AAA4BBB,-1/2,20/2",
11891194
"AAA4BBB,1/2,-1/2",

Lib/zoneinfo/_zoneinfo.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -707,7 +707,7 @@ def _parse_dst_start_end(dststr):
707707
type = date[:1]
708708
if type == "M":
709709
n_is_julian = False
710-
m = re.fullmatch(r"M(\d{1,2})\.(\d).(\d)", date, re.ASCII)
710+
m = re.fullmatch(r"M(\d{1,2})\.(\d)\.(\d)", date, re.ASCII)
711711
if m is None:
712712
raise ValueError(f"Invalid dst start/end date: {dststr}")
713713
date_offset = tuple(map(int, m.groups()))
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
Fixed a parity bug in the pure-Python :mod:`zoneinfo` implementation, which
2+
accepted a POSIX TZ ``Mm.w.d`` transition rule whose third separator was not a
3+
period (for example ``M3.2X0``). Only the first period was escaped in the
4+
regular expression, so the third one matched any character. Such a string is
5+
invalid per POSIX and is already rejected by the C accelerator. Patch by
6+
tonghuaroot.

0 commit comments

Comments
 (0)