Repository navigation
Commit 43e69f4
committed
gh-158500: Reject trailing characters in date.fromisoformat()
date.fromisoformat() accepts strings of length 7, 8 or 10, but the date
parsers never checked that the whole string was consumed. A 10-character
string without a "-" after the year was parsed as an 8-character basic
format date and its last two characters were dropped, so
date.fromisoformat('2020010112') returned date(2020, 1, 1).
Check that the parser stopped exactly at the end of the date in both the
C and pure-Python implementations.
The pure-Python datetime.fromisoformat() had a similar problem: a date
followed by a single character (such as '2020-01-01T') was accepted
because the empty time part was skipped. Parse the time whenever
something follows the date, as the C implementation does.1 parent 3acc941 commit 43e69f4
4 files changed
Lines changed: 30 additions & 1 deletion
File tree
- Lib
- test
- Misc/NEWS.d/next/Library
- Modules
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
396 | 396 | | |
397 | 397 | | |
398 | 398 | | |
| 399 | + | |
| 400 | + | |
| 401 | + | |
| 402 | + | |
399 | 403 | | |
400 | 404 | | |
401 | 405 | | |
| |||
406 | 410 | | |
407 | 411 | | |
408 | 412 | | |
| 413 | + | |
| 414 | + | |
| 415 | + | |
| 416 | + | |
409 | 417 | | |
410 | 418 | | |
411 | 419 | | |
| |||
1984 | 1992 | | |
1985 | 1993 | | |
1986 | 1994 | | |
1987 | | - | |
| 1995 | + | |
1988 | 1996 | | |
1989 | 1997 | | |
1990 | 1998 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
2236 | 2236 | | |
2237 | 2237 | | |
2238 | 2238 | | |
| 2239 | + | |
| 2240 | + | |
| 2241 | + | |
| 2242 | + | |
2239 | 2243 | | |
2240 | 2244 | | |
2241 | 2245 | | |
| |||
3977 | 3981 | | |
3978 | 3982 | | |
3979 | 3983 | | |
| 3984 | + | |
| 3985 | + | |
| 3986 | + | |
| 3987 | + | |
| 3988 | + | |
3980 | 3989 | | |
3981 | 3990 | | |
3982 | 3991 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
977 | 977 | | |
978 | 978 | | |
979 | 979 | | |
| 980 | + | |
| 981 | + | |
| 982 | + | |
| 983 | + | |
980 | 984 | | |
981 | 985 | | |
982 | 986 | | |
| |||
997 | 1001 | | |
998 | 1002 | | |
999 | 1003 | | |
| 1004 | + | |
| 1005 | + | |
| 1006 | + | |
1000 | 1007 | | |
1001 | 1008 | | |
1002 | 1009 | | |
| |||
0 commit comments