Skip to content

fix: reject repeated duration components in the Rust parser - #1005

Open
vzer200 wants to merge 1 commit into
python-pendulum:masterfrom
vzer200:fix/reject-repeated-duration-components
Open

fix: reject repeated duration components in the Rust parser#1005
vzer200 wants to merge 1 commit into
python-pendulum:masterfrom
vzer200:fix/reject-repeated-duration-components

Conversation

@vzer200

@vzer200 vzer200 commented Sep 8, 2026

Copy link
Copy Markdown

The Rust parser accepts P12M4M as four months and PT12M3M1M as sixteen minutes, while the Python fallback rejects both. Track consumed units independently of their values so repeated components and reversed components after zero (such as PT0M1H) raise ParserError. Reset that state at T to keep months and minutes independent.

Addresses the repeated-component portion of #833. Overflow, empty PT, week-mixing permissiveness and arithmetic are unchanged.

Validation on Windows with Python 3.12.14 and Rust 1.98.1:

  • 20 new invalid inputs fail against the original native parser; all 29 duration tests pass after the fix and with the Python fallback.
  • Complete native and fallback suites: each 1,860 passed, 5 skipped.
  • Independent review: 112 related tests passed; 5,236 inputs through both public parsing entry points found no new behavior differences or changes to successful baseline values. Existing fallback fraction/week differences remain.
  • Locked mypy, pinned Ruff and rustfmt pass. Strict Clippy reports the same existing needless_late_init at src/python/helpers.rs:90 on baseline and patch; allowing only that lint passes. No suppression was added to the repository.

Pull Request Check List

  • Added tests for changed code.
  • Updated documentation for changed code. This restores rejection of invalid component sequences; no new API or supported format is introduced.

Prepared with Codex. A separate agent reviewed the source and ran independent baseline comparisons before submission.

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.

1 participant