Skip to content

fix: don't invent a day under STRICT_PARSING - #1347

Open
apoorva-01 wants to merge 1 commit into
scrapinghub:masterfrom
apoorva-01:fix-strict-parsing-month-year
Open

fix: don't invent a day under STRICT_PARSING#1347
apoorva-01 wants to merge 1 commit into
scrapinghub:masterfrom
apoorva-01:fix-strict-parsing-month-year

Conversation

@apoorva-01

Copy link
Copy Markdown

parse("10/2017", settings={"STRICT_PARSING": True}) gives 2017-10-10 instead of None. Only for YMD locales like zh (en is already fine).

What happens: "10/2017" leaves one spare token ("10") and the back-fill reuses it for both the missing month and day, so the date looks complete and the strict check never fires.

Fix: under STRICT_PARSING/REQUIRE_PARTS, use each leftover token only once. Day stays unset, so it's rejected.

Kept it scoped to the strict path so non-strict output doesn't change (zh still gives 2017-10-10). Wider fix would stop the reuse everywhere and match en at 2017-10-02, but that shifts default behavior, so your call. Happy to widen it.

Tests at the parse() level, fail on master, pass here.

Fixes #850

A YMD locale left a spare token that got reused for both the missing
month and day, so "10/2017" slipped through as 2017-10-10. Only reuse a
leftover token once when parts are enforced.
@codecov

codecov Bot commented Jul 22, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 97.11%. Comparing base (273eb23) to head (49bc264).
⚠️ Report is 3 commits behind head on master.

Additional details and impacted files
@@           Coverage Diff           @@
##           master    #1347   +/-   ##
=======================================
  Coverage   97.11%   97.11%           
=======================================
  Files         235      235           
  Lines        2910     2913    +3     
=======================================
+ Hits         2826     2829    +3     
  Misses         84       84           

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

STRICT_PARSING failed with MM/YYYY format

2 participants