GeezerVison is showing github.com — gh-152847: Reject POSIX TZ rule with non-digit day-of-year in `_zonei… · python/cpython@31864bd
File treeExpand file treeCollapse file tree Open diff view settings Expand file treeCollapse file tree Open diff view settings Collapse file Copy file name to clipboardExpand all lines: Lib/test/test_zoneinfo/test_zoneinfo.py +21Lines changed: 21 additions & 0 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -1111,6 +1111,9 @@ def test_extreme_tzstr(self): | 1111 | 1111 | "AAA4BBB,J1/2,J1/14", | 1112 | 1112 | "AAA4BBB,J20/2,J365/2", | 1113 | 1113 | "AAA4BBB,J365/2,J365/14", | | 1114 | + # Leading-zero day-of-year | | 1115 | + "AAA4BBB,J001/2,J065/2", | | 1116 | + "AAA4BBB,001/2,065/2", | 1114 | 1117 | # Extreme transition hour | 1115 | 1118 | "AAA4BBB,J60/167,J300/2", | 1116 | 1119 | "AAA4BBB,J60/+167,J300/2", | @@ -1209,6 +1212,15 @@ def test_invalid_tzstr(self): | 1209 | 1212 | # Invalid julian offset | 1210 | 1213 | "AAA4BBB,J0/2,J20/2", | 1211 | 1214 | "AAA4BBB,J20/2,J366/2", | | 1215 | + # gh-152847: non-digit day-of-year | | 1216 | + "AAA4BBB,J1_0,J300/2", | | 1217 | + "AAA4BBB,J60/2,J30_0/2", | | 1218 | + "AAA4BBB,1_0,J300/2", | | 1219 | + "AAA4BBB,J+1,J300/2", | | 1220 | + "AAA4BBB,J 1,J300/2", | | 1221 | + "AAA4BBB, 1,J300/2", | | 1222 | + "AAA4BBB,J0001,J300/2", | | 1223 | + "AAA4BBB,0001,J300/2", | 1212 | 1224 | # Invalid transition time | 1213 | 1225 | "AAA4BBB,J60/2/3,J300/2", | 1214 | 1226 | "AAA4BBB,J60/2,J300/2/3", | @@ -1248,6 +1260,15 @@ def test_invalid_tzstr_non_ascii_abbr(self): | 1248 | 1260 | with self.assertRaisesRegex(ValueError, expected): | 1249 | 1261 | self.zone_from_tzstr(tzstr, encoding="utf-8") | 1250 | 1262 |
| | 1263 | + def test_invalid_tzstr_non_ascii_dst_date(self): | | 1264 | + tzstr = "AAA4BBB,J١,J300/2" | | 1265 | + if self.module is py_zoneinfo: | | 1266 | + expected = re.escape(tzstr) | | 1267 | + else: | | 1268 | + expected = re.escape(repr(tzstr.encode("utf-8"))) | | 1269 | + with self.assertRaisesRegex(ValueError, expected): | | 1270 | + self.zone_from_tzstr(tzstr, encoding="utf-8") | | 1271 | + | 1251 | 1272 | @classmethod | 1252 | 1273 | def _populate_test_cases(cls): | 1253 | 1274 | # This method uses a somewhat unusual style in that it populates the | |
Collapse file Copy file name to clipboardExpand all lines: Lib/zoneinfo/_zoneinfo.py +2Lines changed: 2 additions & 0 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -720,6 +720,8 @@ def _parse_dst_start_end(dststr): | 720 | 720 | else: | 721 | 721 | n_is_julian = False | 722 | 722 |
| | 723 | + if re.fullmatch(r"\d{1,3}", date, re.ASCII) is None: | | 724 | + raise ValueError(f"Invalid dst start/end date: {dststr}") | 723 | 725 | doy = int(date) | 724 | 726 | offset = _DayOffset(doy, n_is_julian) | 725 | 727 |
| |
Collapse file Copy file name to clipboard +3Lines changed: 3 additions & 0 deletions - Display the source diff
- Display the rich diff
| Original file line number | Diff line number | Diff line change |
|---|
| | 1 | +Reject a POSIX TZ transition rule with non-digit characters in the | | 2 | +day-of-year field in the pure-Python :mod:`zoneinfo` parser. Patch by | | 3 | +tonghuaroot. |
|