Title: zoneinfo: pure-Python POSIX TZ `Mm.w.d` rule accepts a non-`.` week/day separator (C rejects) · Issue #152246 · python/cpython · GitHub
Open Graph Title: zoneinfo: pure-Python POSIX TZ `Mm.w.d` rule accepts a non-`.` week/day separator (C rejects) · Issue #152246 · python/cpython
X Title: zoneinfo: pure-Python POSIX TZ `Mm.w.d` rule accepts a non-`.` week/day separator (C rejects) · Issue #152246 · python/cpython
Description: Bug report The pure-Python zoneinfo parser accepts a POSIX TZ Mm.w.d transition rule whose third separator is not ., while the C accelerator (and POSIX) rejects it. Reproduced on main (3.16.0a0), from_file footer path through _parse_tz_s...
Open Graph Description: Bug report The pure-Python zoneinfo parser accepts a POSIX TZ Mm.w.d transition rule whose third separator is not ., while the C accelerator (and POSIX) rejects it. Reproduced on main (3.16.0a0), f...
X Description: Bug report The pure-Python zoneinfo parser accepts a POSIX TZ Mm.w.d transition rule whose third separator is not ., while the C accelerator (and POSIX) rejects it. Reproduced on main (3.16.0a0), f...
Opengraph URL: https://github.com/python/cpython/issues/152246
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"zoneinfo: pure-Python POSIX TZ `Mm.w.d` rule accepts a non-`.` week/day separator (C rejects)","articleBody":"# Bug report\n\nThe pure-Python `zoneinfo` parser accepts a POSIX TZ `Mm.w.d` transition rule whose third separator is not `.`, while the C accelerator (and POSIX) rejects it.\n\nReproduced on `main` (3.16.0a0), `from_file` footer path through `_parse_tz_str` -> `_parse_dst_start_end`:\n\n```\npython: 3.16.0a0\ntzstr : EST5EDT,M3.2X0,M11.1.0\n\npure zoneinfo._zoneinfo.ZoneInfo.from_file: ZoneInfo(key='EST5EDT,M3.2X0,M11.1.0') -> ACCEPTED\nC _zoneinfo.ZoneInfo.from_file: ValueError: Malformed transition rule in TZ string: b'EST5EDT,M3.2X0,M11.1.0'\n```\n\nThe pure parser also accepts `M3.2!0`, `M3.2-0`, `M3.2:0` and a bad separator in the second rule (`M11.1X0`); the C accelerator rejects all of them.\n\n## Cause\n\n`Lib/zoneinfo/_zoneinfo.py:710`:\n\n```python\nm = re.fullmatch(r\"M(\\d{1,2})\\.(\\d).(\\d)\", date, re.ASCII)\n```\n\nThe first separator is escaped (`\\.`) but the third is a bare `.`, which in a regex matches any single character. So `M3.2X0` matches with week `2`, day `0`, and the separator `X` consumed by the wildcard.\n\n## Which side is wrong\n\nThe pure parser is wrong. POSIX (IEEE Std 1003.1-2024, Issue 8, Base Definitions, 8.3 \"Other Environment Variables\", the `TZ` `Mm.w.d` rule) specifies the form `Mm.w.d` with literal `.` separators between month, week, and day. The C accelerator already enforces both periods at `Modules/_zoneinfo.c:1862` and `Modules/_zoneinfo.c:1868`:\n\n```c\nif (*ptr++ != '.') {\n return -1;\n}\n```\n\nso the pure path should match.\n\n## Fix\n\nEscape the third separator so it is a literal `.`:\n\n```python\nm = re.fullmatch(r\"M(\\d{1,2})\\.(\\d)\\.(\\d)\", date, re.ASCII)\n```\n\nNon-breaking: every well-formed `Mm.w.d` rule and all bundled IANA zones still parse; only the previously-accepted malformed separators now raise, matching the C accelerator.\n\n## Related\n\nDistinct from #152212 / PR #152213, which fix the separate missing-STD-offset parity gap. This is the `Mm.w.d` separator regex.\n\n\u003c!-- gh-linked-prs -->\n### Linked PRs\n* gh-152247\n* gh-152265\n* gh-152266\n* gh-152267\n\u003c!-- /gh-linked-prs -->\n","author":{"url":"https://github.com/tonghuaroot","@type":"Person","name":"tonghuaroot"},"datePublished":"2026-06-26T04:49:56Z","url":"https://github.com/python/cpython/issues/152246"}
| react-profiling | 0 |
| react-import-map | react,react-dom,react-dom/client,react-dom/profiling,react-is,react/compiler-runtime,react/jsx-dev-runtime,react/jsx-runtime,scheduler@b8488ee2c322 |
| route-pattern | /_view_fragments/issues/show/:user_id/:repository/:id/issue_layout(.:format) |
| route-controller | voltron_issues_fragments |
| route-action | issue_layout |
| fetch-nonce | v2:f003bf19-d471-de4f-5c88-180db5c5fc37 |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | 8216:EA06E:4C75D34:60D4715:6B023F2A |
| html-safe-nonce | c5593d0fbd5a6325b3d9801864c8888eede3cdaf1afd19f60e9cb4b24f038ef6 |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiI4MjE2OkVBMDZFOjRDNzVEMzQ6NjBENDcxNTo2QjAyM0YyQSIsInZpc2l0b3JfaWQiOiI1ODU2ODk0MTkxNDkzMzMyNzc4IiwicmVnaW9uX2VkZ2UiOiJpYWQiLCJyZWdpb25fcmVuZGVyIjoiaWFkIn0= |
| visitor-hmac | 7ebb3eb71b163701715380fecdc7233566315f827cddb9590397af35fb877d98 |
| hovercard-subject-tag | issue:4749335664 |
| github-keyboard-shortcuts | repository,issues,copilot |
| google-site-verification | Apib7-x98H0j5cPqHWwSMm6dNU4GmODRoqxLiDzdx9I |
| octolytics-url | https://collector.github.com/github/collect |
| analytics-location | / |
| fb:app_id | 1401488693436528 |
| apple-itunes-app | app-id=1477376905, app-argument=https://github.com/_view_fragments/issues/show/python/cpython/152246/issue_layout |
| twitter:image | https://opengraph.githubassets.com/b7fcaebbbc0decedbe6cb13b87a31c7723c03c15d6594af496965c22d1f66852/python/cpython/issues/152246 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/b7fcaebbbc0decedbe6cb13b87a31c7723c03c15d6594af496965c22d1f66852/python/cpython/issues/152246 |
| og:image:alt | Bug report The pure-Python zoneinfo parser accepts a POSIX TZ Mm.w.d transition rule whose third separator is not ., while the C accelerator (and POSIX) rejects it. Reproduced on main (3.16.0a0), f... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | tonghuaroot |
| hostname | github.com |
| expected-hostname | github.com |
| None | 87e774ee7c6b3bee0490394e4d3e57ec9dbc956f74b87ea685dc8996c1676456 |
| turbo-cache-control | no-preview |
| go-import | github.com/python/cpython git https://github.com/python/cpython.git |
| octolytics-dimension-user_id | 1525981 |
| octolytics-dimension-user_login | python |
| octolytics-dimension-repository_id | 81598961 |
| octolytics-dimension-repository_nwo | python/cpython |
| octolytics-dimension-repository_public | true |
| octolytics-dimension-repository_is_fork | false |
| octolytics-dimension-repository_network_root_id | 81598961 |
| octolytics-dimension-repository_network_root_nwo | python/cpython |
| turbo-body-classes | logged-out env-production page-responsive |
| disable-turbo | false |
| browser-stats-url | https://api.github.com/_private/browser/stats |
| browser-errors-url | https://api.github.com/_private/browser/errors |
| release | 423dbb54c5e7bfecc838eb387c1435eb3d0e760d |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
| react-app-name | issues |
Links:
Viewport: width=device-width