mirror of
https://github.com/beetbox/beets.git
synced 2026-07-16 15:21:28 -04:00
Fix uncaught KeyError on date queries containing a stray pipe
The relative-date regex used character classes [+|-] and [y|m|w|d], which mistakenly treat | as a literal member rather than alternation. As a result a value like added:2000|2001 (as a user might type expecting | to mean "or") captured | as the relative-date unit and crashed with an uncaught KeyError in Period.parse instead of raising the documented InvalidQueryArgumentValueError. Remove the stray | from both character classes so malformed date strings fall through to the normal invalid-date error path. Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
@@ -704,7 +704,7 @@ class Period:
|
||||
"w": 7,
|
||||
"d": 1,
|
||||
}
|
||||
relative_re = "(?P<sign>[+|-]?)(?P<quantity>[0-9]+)(?P<timespan>[y|m|w|d])"
|
||||
relative_re = "(?P<sign>[+-]?)(?P<quantity>[0-9]+)(?P<timespan>[ymwd])"
|
||||
|
||||
def __init__(self, date: datetime, precision: str) -> None:
|
||||
"""Create a period with the given date (a `datetime` object) and
|
||||
|
||||
@@ -88,6 +88,11 @@ Bug fixes
|
||||
- :doc:`plugins/smartplaylist`: ``splupdate`` no longer crashes with
|
||||
``TypeError: unhashable type: 'list'`` when a playlist configuration includes
|
||||
a ``playlist:`` query. :bug:`5354`
|
||||
- A date query containing a stray ``|`` (for example ``added:2000|2001``, as
|
||||
might be typed by a user expecting ``|`` to mean "or") now raises a clean "a
|
||||
valid date/time string" error instead of crashing with an uncaught
|
||||
``KeyError``. A ``|`` was being accepted as a relative-date unit due to a
|
||||
regular expression character-class typo.
|
||||
|
||||
..
|
||||
For plugin developers
|
||||
|
||||
@@ -231,6 +231,14 @@ class DateQueryConstructTest(unittest.TestCase):
|
||||
with pytest.raises(InvalidQueryArgumentValueError):
|
||||
DateQuery("added", q)
|
||||
|
||||
def test_pipe_in_relative_date_query(self):
|
||||
# A stray "|" (e.g. a user expecting OR syntax like "added:2000|2001")
|
||||
# must raise a clean InvalidQueryArgumentValueError rather than an
|
||||
# uncaught KeyError from the relative-date parser.
|
||||
for q in ["2000|2001", "1|", "5|3d"]:
|
||||
with pytest.raises(InvalidQueryArgumentValueError):
|
||||
DateQuery("added", q)
|
||||
|
||||
def test_datetime_uppercase_t_separator(self):
|
||||
date_query = DateQuery("added", "2000-01-01T12")
|
||||
assert date_query.interval.start == datetime(2000, 1, 1, 12)
|
||||
|
||||
Reference in New Issue
Block a user