Stop query date regex from matching > 4 digit year #4162
Merged
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.
Some queries are ambiguous between dates and numbers, e.g. "2002" could be a year or a number. In order to simplify quering parsing, Quod Libet stores these ambiguous subqueries as the "NumexprNumberOrDate" type.
When parsing a query, Quod Libet will use this type if the string matches a regex for parsing dates. However, before this commit, the regex will match the first four digits of any four or more digit number. This results in a parsing error for large numbers because of the remaining digits after the four that get matched and parsed.
Instead, use a negative lookahead to limit the year part of the date to four digits. Quod Libet will fall back to using an unambiguous number representation for large numbers.
As an alternative, I tried to allow >4 digit years for future-proofing, but a 4 digit year assumption is baked in too deeply, e.g. in Python's
strptime
function.Fixes #4161.
Check-list
master