make relative-date regex digit quantifiers possessive#1335
Merged
serhii73 merged 3 commits intoJun 9, 2026
Conversation
Open
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## master #1335 +/- ##
==========================================
- Coverage 97.11% 97.11% -0.01%
==========================================
Files 235 235
Lines 2912 2909 -3
==========================================
- Hits 2828 2825 -3
Misses 84 84 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
serhii73
approved these changes
Jun 9, 2026
Collaborator
|
Thanks! |
Merged
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.
The relative-date matchers are built from
\d+[.,]?\d*and run across the whole input:PATTERNinfreshness_date_parserviafindall/sub, and thesplit_relativeregex indictionary.pyviasplit. On a long run of digits the two adjacent digit quantifiers backtrack without ever changing the match, so cost grows superlinearly.Repro:
dateparser.parse('9' * 3200), or any long digit run reaching the relative parser.Cause: the expression is matched at every position; splitting
\d+against\d*over a digit run backtracks quadratically insplit, near-cubically for the freshnessfindall.Fix: make the digit quantifiers possessive (
\d++/\d*+). A digit run can only be followed by[.,]or the literal unit text, so giving digits back can never complete a match.PATTERN.findall('9' * 3200)goes from ~23s to ~0.02s; match results are unchanged and the existing suite passes.