René's URL Explorer Experiment


Title: gh-158500: Reject trailing characters in date.fromisoformat() by iamsaugatpandey · Pull Request #160737 · python/cpython · GitHub

Open Graph Title: gh-158500: Reject trailing characters in date.fromisoformat() by iamsaugatpandey · Pull Request #160737 · python/cpython

X Title: gh-158500: Reject trailing characters in date.fromisoformat() by iamsaugatpandey · Pull Request #160737 · python/cpython

Description: date.fromisoformat() accepts strings of length 7, 8 or 10, but neither parser checks that it read the whole string. A 10-character string without a - after the year goes down the basic-format path, which reads YYYYMMDD (or YYYYWwwD) and returns, ignoring the last two characters. So a truncated or mistyped timestamp turns into a plausible but wrong date: >>> from datetime import date >>> date.fromisoformat('2020010112') # e.g. a YYYYMMDDHH stamp datetime.date(2020, 1, 1) >>> date.fromisoformat('2020W011xx') datetime.date(2019, 12, 30) >>> date.fromisoformat('20200101é') # C only: 9 characters, but 10 bytes in UTF-8 datetime.date(2020, 1, 1) With this change, all three raise ValueError: Invalid isoformat string, as datetime.fromisoformat() already does for the same input. The fix checks that the parser stopped exactly at the end of the date, in both parse_isoformat_date() in C and _parse_isoformat_date() in _pydatetime. datetime.fromisoformat() uses the same function for its date part, but there the date always ends at the separator for valid strings. I compared the C module before and after on ~300k fuzzed strings: only date.fromisoformat() results changed (all from accepted to rejected), and datetime.fromisoformat() results did not change at all. While adding the tests I found that the pure-Python datetime.fromisoformat() has a similar problem. It skipped time parsing whenever the time part was empty, so a date followed by any single character was accepted: >>> import _pydatetime >>> _pydatetime.datetime.fromisoformat('2020-01-01T') datetime.datetime(2020, 1, 1, 0, 0) >>> _pydatetime.datetime.fromisoformat('2021-01-071') datetime.datetime(2021, 1, 7, 0, 0) The C implementation already rejects these. It now parses the time whenever something follows the date, the same as C. It's the same "didn't consume the whole input" bug, so I kept it here, but I'm happy to split it out if you'd prefer. Tests are added to test_fromisoformat_fails and test_fromisoformat_fails_datetime, so they run against both implementations. Issue: gh-158500

Open Graph Description: date.fromisoformat() accepts strings of length 7, 8 or 10, but neither parser checks that it read the whole string. A 10-character string without a - after the year goes down the basic-format path,...

X Description: date.fromisoformat() accepts strings of length 7, 8 or 10, but neither parser checks that it read the whole string. A 10-character string without a - after the year goes down the basic-format path,...

Opengraph URL: https://github.com/python/cpython/pull/160737

X: @github

direct link

Domain: github.com

react-profiling0
react-import-mapreact,react-dom,react-dom/client,react-dom/profiling,react-is,react/compiler-runtime,react/jsx-dev-runtime,react/jsx-runtime,scheduler@b8488ee2c322
route-pattern/:user_id/:repository/pull/:id/files(.:format)
route-controllerpull_requests
route-actionfiles
fetch-noncev2:1c836274-4499-fe60-3e1b-fc6134dd731d
current-catalog-service-hashae870bc5e265a340912cde392f23dad3671a0a881730ffdadd82f2f57d81641b
request-id8FA4:269AD9:381762D:4ADDED6:6B0215DC
html-safe-nonce160a304d82a6f1e10ef2b5073d8a3e72106c33625ff75db84a1dc1073762cb8d
visitor-payloadeyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiI4RkE0OjI2OUFEOTozODE3NjJEOjRBRERFRDY6NkIwMjE1REMiLCJ2aXNpdG9yX2lkIjoiMzI3NzMzMjcwMTc1NzE4MzQ1MiIsInJlZ2lvbl9lZGdlIjoiaWFkIiwicmVnaW9uX3JlbmRlciI6ImlhZCJ9
visitor-hmacfdb63d9d43919511939ab6ca873a02f0b9446cc2af0178f14c4765aa23b68e08
hovercard-subject-tagpull_request:5025078505
github-keyboard-shortcutsrepository,pull-request-list,pull-request-conversation,pull-request-files-changed,copilot
google-site-verificationApib7-x98H0j5cPqHWwSMm6dNU4GmODRoqxLiDzdx9I
octolytics-urlhttps://collector.github.com/github/collect
analytics-location///pull_requests/show/files
fb:app_id1401488693436528
apple-itunes-appapp-id=1477376905, app-argument=https://github.com/python/cpython/pull/160737/files
twitter:imagehttps://avatars.githubusercontent.com/u/39925335?s=400&v=4
twitter:cardsummary_large_image
og:imagehttps://avatars.githubusercontent.com/u/39925335?s=400&v=4
og:image:altdate.fromisoformat() accepts strings of length 7, 8 or 10, but neither parser checks that it read the whole string. A 10-character string without a - after the year goes down the basic-format path,...
og:site_nameGitHub
og:typeobject
hostnamegithub.com
expected-hostnamegithub.com
None87e774ee7c6b3bee0490394e4d3e57ec9dbc956f74b87ea685dc8996c1676456
turbo-cache-controlno-preview
diff-viewunified
go-importgithub.com/python/cpython git https://github.com/python/cpython.git
octolytics-dimension-user_id1525981
octolytics-dimension-user_loginpython
octolytics-dimension-repository_id81598961
octolytics-dimension-repository_nwopython/cpython
octolytics-dimension-repository_publictrue
octolytics-dimension-repository_is_forkfalse
octolytics-dimension-repository_network_root_id81598961
octolytics-dimension-repository_network_root_nwopython/cpython
turbo-body-classeslogged-out env-production page-responsive full-width
disable-turbotrue
browser-stats-urlhttps://api.github.com/_private/browser/stats
browser-errors-urlhttps://api.github.com/_private/browser/errors
release423dbb54c5e7bfecc838eb387c1435eb3d0e760d
ui-targetfull
theme-color#1e2327
color-schemelight dark

Links:

Skip to contenthttps://github.com/python/cpython/pull/160737/files#start-of-content
https://github.com/
Sign inhttps://github.com/login?return_to=https%3A%2F%2Fgithub.com%2Fpython%2Fcpython%2Fpull%2F160737%2Ffiles
GitHubRepository hosting, code review, and collaborationhttps://github.com/platform
CopilotAI coding agent for tasks, projects, and automated workhttps://github.com/features/copilot
ActionsCI/CD and automationhttps://github.com/features/actions
Code QualityQuality analysis, fixes, and enforcementhttps://github.com/features/code-quality
CodespacesCloud development environmentshttps://github.com/features/codespaces
Code SecurityVulnerability detection and remediationhttps://github.com/security/advanced-security/code-security
Secret ProtectionSecret scanning and leak preventionhttps://github.com/security/advanced-security/secret-protection
All Featureshttps://github.com/features
Documentationhttps://docs.github.com/en
Traininghttps://learn.github.com/skills
Certificationshttps://learn.github.com/credentials
Build with Copilothttps://github.com/features/ai
Customize Copilothttps://docs.github.com/en/copilot/how-tos/copilot-on-github/customize-copilot/customize-copilot-overview
Integrationshttps://github.com/marketplace
Trending reposhttps://github.com/trending
GitHub Sponsorshttps://github.com/open-source/sponsors
Developer articleshttps://github.com/resources/articles
ChangelogYour source for the latest features, improvements, and fixes across GitHub products, all in one place.https://github.blog/changelog/
Enterpriseshttps://github.com/enterprise
Teamhttps://github.com/team
Startupshttps://github.com/enterprise/startups
Nonprofitshttps://github.com/solutions/industry/nonprofits
Healthcarehttps://github.com/solutions/industry/healthcare
Financial serviceshttps://github.com/solutions/industry/financial-services
Manufacturinghttps://github.com/solutions/industry/manufacturing
Governmenthttps://github.com/solutions/industry/government
See all industrieshttps://github.com/solutions/industry
Why GitHubhttps://github.com/why-github
Customer Storieshttps://github.com/customer-stories
Business insightshttps://github.com/solutions/executive-insights
Trust Centerhttps://github.com/trust-center
GitHub Advanced SecurityEnterprise-grade code securityhttps://github.com/security/advanced-security
Copilot for businessEnterprise-grade AI featureshttps://github.com/features/copilot/copilot-business
Premium SupportEnterprise-grade 24/7 supporthttps://github.com/enterprise/premium-support
Documentationhttps://docs.github.com/en
Resource centerhttps://github.com/resources
Bloghttps://github.blog/
Events & webinarshttps://github.com/resources/events
Community Forumhttps://github.com/orgs/community/discussions
Customer Storieshttps://github.com/customer-stories
Integrationshttps://github.com/marketplace
Customer supporthttps://help.github.com/
Traininghttps://learn.github.com/skills
GitHub Statushttps://www.githubstatus.com/
Abouthttps://github.com/about
Partnershttps://github.com/partners
Changeloghttps://github.blog/changelog/
GitHub UniverseThe event for developers, by developers — talks, workshops, and what’s next for GitHub.https://githubuniverse.com/
Pricinghttps://github.com/pricing
Sign inhttps://github.com/login?return_to=https%3A%2F%2Fgithub.com%2Fpython%2Fcpython%2Fpull%2F160737%2Ffiles
Sign uphttps://github.com/signup?ref_cta=Sign+up&ref_loc=header+logged+out&ref_page=%2F%3Cuser-name%3E%2F%3Crepo-name%3E%2Fpull_requests%2Fshow%2Ffiles&source=header-repo&source_repo=python%2Fcpython
Reloadhttps://github.com/python/cpython/pull/160737/files
Reloadhttps://github.com/python/cpython/pull/160737/files
Reloadhttps://github.com/python/cpython/pull/160737/files
pythonhttps://github.com/python
cpythonhttps://github.com/python/cpython
Codehttps://github.com/python/cpython
Issues5k+ (5k+)https://github.com/python/cpython/issues
Pull requests2.4k (2.4k)https://github.com/python/cpython/pulls
Actionshttps://github.com/python/cpython/actions
Projectshttps://github.com/python/cpython/projects
Security and qualityhttps://github.com/python/cpython/security
Insightshttps://github.com/python/cpython/insights
Sign up for GitHub https://github.com/signup?return_to=%2Fpython%2Fcpython%2Fissues%2Fnew%2Fchoose
terms of servicehttps://docs.github.com/terms
privacy statementhttps://docs.github.com/privacy
Sign inhttps://github.com/login?return_to=%2Fpython%2Fcpython%2Fissues%2Fnew%2Fchoose
StanFromIrelandhttps://github.com/StanFromIreland
python:mainhttps://github.com/python/cpython/tree/main
iamsaugatpandey:gh-158500-date-fromisoformat-trailinghttps://github.com/iamsaugatpandey/cpython/tree/gh-158500-date-fromisoformat-trailing
Conversation 10 https://github.com/python/cpython/pull/160737
Commits 2 https://github.com/python/cpython/pull/160737/commits
Checks 66 https://github.com/python/cpython/pull/160737/checks
Files changed https://github.com/python/cpython/pull/160737/files
Please reload this pagehttps://github.com/python/cpython/pull/160737/files
gh-158500: Reject trailing characters in date.fromisoformat() https://github.com/python/cpython/pull/160737/files#top
Show all changes 2 commits https://github.com/python/cpython/pull/160737/files
43e69f4 gh-158500: Reject trailing characters in date.fromisoformat() iamsaugatpandey Oct 26, 2026 https://github.com/python/cpython/pull/160737/commits/43e69f400d6bdffb5743b106e4e075e9f2f9c185
28fe88e Apply suggestion from @StanFromIreland StanFromIreland Nov 6, 2026 https://github.com/python/cpython/pull/160737/commits/28fe88e38f008e3311d12d4830aeaafc0117ed82
Clear filters https://github.com/python/cpython/pull/160737/files
Please reload this pagehttps://github.com/python/cpython/pull/160737/files
Please reload this pagehttps://github.com/python/cpython/pull/160737/files
_pydatetime.py https://github.com/python/cpython/pull/160737/files#diff-5dc97b7989952636b0cd6224bc01469715753358d6e2a9059707f0d06f83b141
datetimetester.py https://github.com/python/cpython/pull/160737/files#diff-917d5d1d1423993f37a643afa9f2a2f9caa3c0f91e06c0d7ebea1b879d53b4ef
2026-10-26-21-37-42.gh-issue-158500.zxyuq5.rst https://github.com/python/cpython/pull/160737/files#diff-8abc72cf319b6d3a849e510c9778d8a434daab87bf1ee3f418fd6fba405fc37a
_datetimemodule.c https://github.com/python/cpython/pull/160737/files#diff-3ee250e3806e884518fd872e9148baf532de6ec54c1cdb4e7679fbb2869d9c47
https://github.com/python/cpython/blob/main/.github/CODEOWNERS#L433
Lib/_pydatetime.pyhttps://github.com/python/cpython/pull/160737/files#diff-5dc97b7989952636b0cd6224bc01469715753358d6e2a9059707f0d06f83b141
View file https://github.com/iamsaugatpandey/cpython/blob/28fe88e38f008e3311d12d4830aeaafc0117ed82/Lib/_pydatetime.py
Open in desktop https://desktop.github.com
https://github.co/hiddenchars
https://github.com/python/cpython/pull/160737/{{ revealButtonHref }}
https://github.com/python/cpython/pull/160737/files#diff-5dc97b7989952636b0cd6224bc01469715753358d6e2a9059707f0d06f83b141
https://github.com/python/cpython/pull/160737/files#diff-5dc97b7989952636b0cd6224bc01469715753358d6e2a9059707f0d06f83b141
https://github.com/python/cpython/pull/160737/files#diff-5dc97b7989952636b0cd6224bc01469715753358d6e2a9059707f0d06f83b141
https://github.com/python/cpython/pull/160737/files#diff-5dc97b7989952636b0cd6224bc01469715753358d6e2a9059707f0d06f83b141
https://github.com/python/cpython/pull/160737/files#diff-5dc97b7989952636b0cd6224bc01469715753358d6e2a9059707f0d06f83b141
https://github.com/python/cpython/blob/main/.github/CODEOWNERS#L434
Lib/test/datetimetester.pyhttps://github.com/python/cpython/pull/160737/files#diff-917d5d1d1423993f37a643afa9f2a2f9caa3c0f91e06c0d7ebea1b879d53b4ef
View file https://github.com/iamsaugatpandey/cpython/blob/28fe88e38f008e3311d12d4830aeaafc0117ed82/Lib/test/datetimetester.py
Open in desktop https://desktop.github.com
https://github.co/hiddenchars
https://github.com/python/cpython/pull/160737/{{ revealButtonHref }}
https://github.com/python/cpython/pull/160737/files#diff-917d5d1d1423993f37a643afa9f2a2f9caa3c0f91e06c0d7ebea1b879d53b4ef
https://github.com/python/cpython/pull/160737/files#diff-917d5d1d1423993f37a643afa9f2a2f9caa3c0f91e06c0d7ebea1b879d53b4ef
https://github.com/python/cpython/pull/160737/files#diff-917d5d1d1423993f37a643afa9f2a2f9caa3c0f91e06c0d7ebea1b879d53b4ef
https://github.com/python/cpython/pull/160737/files#diff-917d5d1d1423993f37a643afa9f2a2f9caa3c0f91e06c0d7ebea1b879d53b4ef
Misc/NEWS.d/next/Library/2026-10-26-21-37-42.gh-issue-158500.zxyuq5.rsthttps://github.com/python/cpython/pull/160737/files#diff-8abc72cf319b6d3a849e510c9778d8a434daab87bf1ee3f418fd6fba405fc37a
View file https://github.com/iamsaugatpandey/cpython/blob/28fe88e38f008e3311d12d4830aeaafc0117ed82/Misc/NEWS.d/next/Library/2026-10-26-21-37-42.gh-issue-158500.zxyuq5.rst
Open in desktop https://desktop.github.com
https://github.co/hiddenchars
https://github.com/python/cpython/pull/160737/{{ revealButtonHref }}
https://github.com/python/cpython/blob/main/.github/CODEOWNERS#L437
Modules/_datetimemodule.chttps://github.com/python/cpython/pull/160737/files#diff-3ee250e3806e884518fd872e9148baf532de6ec54c1cdb4e7679fbb2869d9c47
View file https://github.com/iamsaugatpandey/cpython/blob/28fe88e38f008e3311d12d4830aeaafc0117ed82/Modules/_datetimemodule.c
Open in desktop https://desktop.github.com
https://github.co/hiddenchars
https://github.com/python/cpython/pull/160737/{{ revealButtonHref }}
https://github.com/python/cpython/pull/160737/files#diff-3ee250e3806e884518fd872e9148baf532de6ec54c1cdb4e7679fbb2869d9c47
https://github.com/python/cpython/pull/160737/files#diff-3ee250e3806e884518fd872e9148baf532de6ec54c1cdb4e7679fbb2869d9c47
https://github.com/python/cpython/pull/160737/files#diff-3ee250e3806e884518fd872e9148baf532de6ec54c1cdb4e7679fbb2869d9c47
Please reload this pagehttps://github.com/python/cpython/pull/160737/files
https://github.com
Termshttps://docs.github.com/site-policy/github-terms/github-terms-of-service
Privacyhttps://docs.github.com/site-policy/privacy-policies/github-privacy-statement
Securityhttps://github.com/security
Statushttps://www.githubstatus.com/
Communityhttps://github.community/
Docshttps://docs.github.com/
Contacthttps://support.github.com?tags=dotcom-footer

Viewport: width=device-width


URLs of crawlers that visited me.