Reject non-ASCII digits and trailing newlines in version parsing - #478
Merged
tomschr merged 1 commit intoSep 12, 2026
Merged
Conversation
Co-authored-by: Codex <noreply@openai.com>
Str0k
force-pushed
the
fix/strict-semver-character-validation
branch
from
September 12, 2026 03:42
a3a30d5 to
188383b
Compare
Member
|
Thank you very much @Str0k for your contribution! This is awesome! 🎉 😍 Many thanks! |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Version.parse()currently accepts characters outside the SemVer grammar. For example,Version.is_valid('1.2.3\n')is true, andVersion.parse('1\u0662.2.3')silently converts a mixed ASCII/Arabic-Indic major component to12.2.3. Non-ASCII digits can also survive in prerelease identifiers.The shared regex uses Python's Unicode-aware
\dand$, which may match before a final newline. Compile both strict and optional-component patterns withre.ASCIIand use\Zto require the actual end of the input. These constraints follow the ASCII digit grammar and prerelease requirements in https://semver.org/#backusnaur-form-grammar-for-valid-semver-versions.This intentionally rejects previously accepted malformed input; callers wanting whitespace tolerance can strip it before parsing. No exploit or CVE is claimed.
Validation, Windows / Python 3.12:
0f18aa0; mypy has the same existing missing-backend-stub diagnostic on both revisions.tests/were temporarily materialized as copies for Windows testing, then restored. They are not part of the diff.AI assistance: Codex helped implement and test this change. The reproduction and verification results are supplied for maintainer review.