Thanks to visit codestin.com
Credit goes to github.com

Skip to content

gh-130959: Reject whitespace in fractions, in pure Python fromisoformat() #130962

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 5 commits into from
Mar 11, 2025

Conversation

mgorny
Copy link
Contributor

@mgorny mgorny commented Mar 7, 2025

Fix the pure Python implementation of fromisoformat() to reject any non-digit characters, including whitespace, in the fractional part of time specification. This makes the behavior consistent with the C implementation, and prevents incorrect parsing of these fractions (e.g. .400 would be misinterpreted as .04).

…isoformat()`

Fix the pure Python implementation of `fromisoformat()` to reject any
non-digit characters, including whitespace, in the fractional part
of time specification.  This makes the behavior consistent with the C
implementation, and prevents incorrect parsing of these fractions
(e.g. `.400 ` would be misinterpreted as `.04`).
@pganssle pganssle added 3.12 only security fixes 3.13 bugs and security fixes 3.14 bugs and security fixes and removed awaiting merge labels Mar 8, 2025
@ZeroIntensity ZeroIntensity added needs backport to 3.12 only security fixes needs backport to 3.13 bugs and security fixes and removed 3.12 only security fixes 3.13 bugs and security fixes 3.14 bugs and security fixes labels Mar 8, 2025
Co-authored-by: Peter Bierma <[email protected]>
Co-authored-by: Paul Ganssle <[email protected]>
@mgorny
Copy link
Contributor Author

mgorny commented Mar 8, 2025

Thanks!

mattip pushed a commit to pypy/pypy that referenced this pull request Mar 8, 2025
Fix pure Python implementation of `fromisoformat()` to reject spaces
in fractional part of time specifications.  This matches the behavior
of the C implementation in CPython, and prevents the method from parsing
them incorrectly.

This fixes Django's test suite by enabling a fallback to their own
(working) parser.

Backports: python/cpython#130962
Copy link
Member

@vstinner vstinner left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@vstinner vstinner merged commit 33494b4 into python:main Mar 11, 2025
41 checks passed
@miss-islington-app
Copy link

Thanks @mgorny for the PR, and @vstinner for merging it 🌮🎉.. I'm working now to backport this PR to: 3.12, 3.13.
🐍🍒⛏🤖

@miss-islington-app
Copy link

Sorry, @mgorny and @vstinner, I could not cleanly backport this to 3.13 due to a conflict.
Please backport using cherry_picker on command line.

cherry_picker 33494b4d0dafc34ff4f1c118b7b3b5d8de3dd0f4 3.13

@miss-islington-app
Copy link

Sorry, @mgorny and @vstinner, I could not cleanly backport this to 3.12 due to a conflict.
Please backport using cherry_picker on command line.

cherry_picker 33494b4d0dafc34ff4f1c118b7b3b5d8de3dd0f4 3.12

@bedevere-app
Copy link

bedevere-app bot commented Mar 11, 2025

GH-131076 is a backport of this pull request to the 3.13 branch.

@bedevere-app bedevere-app bot removed the needs backport to 3.13 bugs and security fixes label Mar 11, 2025
@vstinner vstinner removed the needs backport to 3.12 only security fixes label Mar 11, 2025
vstinner pushed a commit to vstinner/cpython that referenced this pull request Mar 11, 2025
…isoformat()` (python#130962)

Fix the pure Python implementation of `fromisoformat()` to reject any
non-digit characters, including whitespace, in the fractional part
of time specification.  This makes the behavior consistent with the C
implementation, and prevents incorrect parsing of these fractions
(e.g. `.400 ` would be misinterpreted as `.04`).

Co-authored-by: Peter Bierma <[email protected]>
Co-authored-by: Paul Ganssle <[email protected]>
(cherry picked from commit 33494b4)
vstinner added a commit that referenced this pull request Mar 11, 2025
…misoformat()` (#130962) (#131076)

gh-130959: Reject whitespace in fractions, in pure Python `fromisoformat()` (#130962)

Fix the pure Python implementation of `fromisoformat()` to reject any
non-digit characters, including whitespace, in the fractional part
of time specification.  This makes the behavior consistent with the C
implementation, and prevents incorrect parsing of these fractions
(e.g. `.400 ` would be misinterpreted as `.04`).

Co-authored-by: Peter Bierma <[email protected]>
Co-authored-by: Paul Ganssle <[email protected]>
(cherry picked from commit 33494b4)

Co-authored-by: Michał Górny <[email protected]>
miss-islington pushed a commit to miss-islington/cpython that referenced this pull request Mar 11, 2025
…n `fromisoformat()` (pythonGH-130962) (pythonGH-131076)

pythongh-130959: Reject whitespace in fractions, in pure Python `fromisoformat()` (pythonGH-130962)

Fix the pure Python implementation of `fromisoformat()` to reject any
non-digit characters, including whitespace, in the fractional part
of time specification.  This makes the behavior consistent with the C
implementation, and prevents incorrect parsing of these fractions
(e.g. `.400 ` would be misinterpreted as `.04`).

Co-authored-by: Peter Bierma <[email protected]>
Co-authored-by: Paul Ganssle <[email protected]>
(cherry picked from commit 33494b4)
(cherry picked from commit 27fd328)

Co-authored-by: Victor Stinner <[email protected]>
Co-authored-by: Michał Górny <[email protected]>
vstinner added a commit that referenced this pull request Mar 11, 2025
…mat()` (GH-130962) (GH-131076) (#131086)

Fix the pure Python implementation of `fromisoformat()` to reject any
non-digit characters, including whitespace, in the fractional part
of time specification.  This makes the behavior consistent with the C
implementation, and prevents incorrect parsing of these fractions
(e.g. `.400 ` would be misinterpreted as `.04`).

(cherry picked from commit 33494b4)
(cherry picked from commit 27fd328)

Co-authored-by: Victor Stinner <[email protected]>
Co-authored-by: Michał Górny <[email protected]>
seehwan pushed a commit to seehwan/cpython that referenced this pull request Apr 16, 2025
…isoformat()` (python#130962)

* pythongh-130959: Reject whitespace in fractions, in pure Python `fromisoformat()`

Fix the pure Python implementation of `fromisoformat()` to reject any
non-digit characters, including whitespace, in the fractional part
of time specification.  This makes the behavior consistent with the C
implementation, and prevents incorrect parsing of these fractions
(e.g. `.400 ` would be misinterpreted as `.04`).

* Add the news entry

* Use a different example to fix Sphinx lint

* Apply suggestions from code review

Co-authored-by: Peter Bierma <[email protected]>
Co-authored-by: Paul Ganssle <[email protected]>

* Try fixing `:func:` ref.

---------

Co-authored-by: Peter Bierma <[email protected]>
Co-authored-by: Paul Ganssle <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants