Skip to content

Commit 33f9057

Browse files
committed
Allow spaces or T in datetime-local value
Fixes #344
1 parent 0f7c773 commit 33f9057

3 files changed

Lines changed: 38 additions & 1 deletion

File tree

‎docs/src/markdown/about/changelog.md‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,8 @@ icon: lucide/scroll-text
2727
per HTML, such values are not valid, so they are treated like a missing value and cannot be out of range.
2828
- **FIX**: Fix `:in-range` and `:out-of-range` raising `ValueError` when a date, month, week, or local date and
2929
time `input` has a year with more digits than Python will convert; such a year is now treated as invalid.
30+
- **FIX**: Fix `:in-range` and `:out-of-range` not recognizing a `datetime-local` value, `min`, or `max` that uses a
31+
single space instead of `T` to separate the date and time.
3032
- **FIX**: Search a form only once for checked radio buttons when matching `:indeterminate` to avoid quadratic time
3133
on forms with many radio button groups.
3234
- **FIX**: `:lang()` now uses the `lang` attribute of SVG elements, as the HTML specification does (with `xml:lang`

‎soupsieve/css_match.py‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@
7171
RE_WEEK = re.compile(r'^(?P<year>[0-9]{4,})-W(?P<week>[0-9]{2})\Z')
7272
RE_DATE = re.compile(r'^(?P<year>[0-9]{4,})-(?P<month>[0-9]{2})-(?P<day>[0-9]{2})\Z')
7373
RE_DATETIME = re.compile(
74-
r'^(?P<year>[0-9]{4,})-(?P<month>[0-9]{2})-(?P<day>[0-9]{2})T(?P<hour>[0-9]{2}):(?P<minutes>[0-9]{2})'
74+
r'^(?P<year>[0-9]{4,})-(?P<month>[0-9]{2})-(?P<day>[0-9]{2})[T ](?P<hour>[0-9]{2}):(?P<minutes>[0-9]{2})'
7575
r'(?::(?P<seconds>[0-9]{2}(?:\.[0-9]{1,3})?))?\Z'
7676
)
7777
RE_WILD_STRIP = re.compile(r'(?:(?:-\*-)(?:\*(?:-|$))*|-\*$)')

‎tests/test_level4/test_in_range.py‎

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -345,3 +345,38 @@ def test_range_trailing_newline(self):
345345
['6'],
346346
flags=util.HTML
347347
)
348+
349+
def test_range_datetime_local_separator(self):
350+
"""A local date and time may separate the date and time with a single `T` or a single space."""
351+
352+
markup = """
353+
<input id="0" type="datetime-local" min="2026-01-01T12:00" max="2026-12-31T12:00" value="2026-06-01 12:00">
354+
<input id="1" type="datetime-local" min="2026-01-01T12:00" value="2025-12-31 12:00">
355+
<input id="2" type="datetime-local" max="2026-01-01T12:00" value="2026-12-31 12:00">
356+
<input id="3" type="datetime-local" min="2026-01-01 12:00" value="2025-12-31T12:00">
357+
<input id="4" type="datetime-local" max="2026-01-01 12:00" value="2026-12-31T12:00">
358+
<input id="5" type="datetime-local" min="2026-06-01 12:00:30" value="2026-06-01 12:00:30.5">
359+
<input id="6" type="datetime-local" min="2026-01-01 12:00" value="2026-01-01T12:00">
360+
<input id="7" type="datetime-local" min="2026-01-01T12:00" value="2025-12-31 12:00">
361+
<input id="8" type="datetime-local" min="2026-01-01T12:00" value="2025-12-31&#9;12:00">
362+
<input id="9" type="datetime-local" min="2026-01-01T12:00" value="2025-12-31&#10;12:00">
363+
<input id="10" type="datetime-local" min="2026-01-01T12:00" value="2025-12-31t12:00">
364+
<input id="11" type="datetime-local" min="2026-01-01T12:00" value="2025-12-31&#160;12:00">
365+
<input id="12" type="datetime-local" min="2026-01-01 12:00" value="2025-12-31T12:00">
366+
"""
367+
368+
# Any other separator is invalid: an invalid value is treated like a
369+
# missing value, and with only an invalid bound there is no range.
370+
self.assert_selector(
371+
markup,
372+
":in-range",
373+
['0', '5', '6', '7', '8', '9', '10', '11'],
374+
flags=util.HTML
375+
)
376+
377+
self.assert_selector(
378+
markup,
379+
":out-of-range",
380+
['1', '2', '3', '4'],
381+
flags=util.HTML
382+
)

0 commit comments

Comments
 (0)