Repository navigation
Reject malformed DATE values in convert_date instead of parsing them - #1301
waw666waw666 wants to merge 1 commit into
Conversation
convert_date() split on '-' and fed the parts to int(), which silently accepts underscores, signs and surrounding whitespace, so malformed values like '2007-02-2_6' came back as date(2007, 2, 26) instead of the original string the docstring promises for illegal values. The other three converters were fixed the same way in PyMySQL#1280 (strict pattern plus fullmatch); convert_date had no pattern at all and was the one left behind. Give it a DATE_RE matching the field widths of DATETIME_RE and require a full match, so only digit-only components reach the date constructor. This also returns incomplete values such as '2007-02' unchanged instead of raising TypeError (issue PyMySQL#1286, superseding the narrower PyMySQL#1287/PyMySQL#1292 for that symptom). Tests: test_convert_date_rejects_non_digit_components and test_convert_date_rejects_incomplete_values in pymysql/tests/test_converters.py, plus a doctest line (fail before the fix, pass after). Server-free suite: 32 passed (baseline 30, only the 2 new tests added). ruff format and ruff check pass.
|
No actionable comments were generated in the recent review. Walkthrough
Merge Risk:
|
convert_date()split on-and fed the parts toint(), whichsilently accepts underscores, signs and surrounding whitespace, so
malformed values like
"2007-02-2_6"came back asdate(2007, 2, 26)instead of the original string the docstring promises for illegal
values. The other three converters were fixed the same way in #1280
(strict pattern plus fullmatch);
convert_datehad no pattern atall and was the one left behind. Give it a
DATE_REmatching thefield widths of
DATETIME_REand require a full match, so onlydigit-only components reach the date constructor. This also returns
incomplete values such as
"2007-02"unchanged instead of raisingTypeError(issue #1286, superseding the narrower #1287/#1292 forthat symptom).
Tests: added
test_convert_date_rejects_non_digit_componentsandtest_convert_date_rejects_incomplete_valuesinpymysql/tests/test_converters.py, plus a doctest line (fail beforethe fix, pass after). Server-free suite: 32 passed (baseline 30,
only the 2 new tests added).
ruff formatandruff checkpass.The integration suite needs a live MySQL server and was not run
locally; the change only touches a pure decoding function.
Summary by CodeRabbit