Fix FI HETU accepting 29 Feb of a non-leap century#2111
Open
jichaowang02-lang wants to merge 1 commit into
Open
Fix FI HETU accepting 29 Feb of a non-leap century#2111jichaowang02-lang wants to merge 1 commit into
jichaowang02-lang wants to merge 1 commit into
Conversation
validate_result checked the date with datetime.strptime(date_part, "%d%m%y"),
which only sees the 2-digit year and maps it to the 2000s. The century is
actually carried by the 7th character (the separator), which strptime never
receives. So 29 Feb of a non-leap century is wrongly accepted: "290200+311B"
denotes 29 February 1800 ("+" = 1800s), but 1800 is not a leap year, yet
strptime validates it as 29 Feb 2000 (which is a leap year).
Resolve the century from the separator and validate the full date. Unknown
separators fall back to the previous strptime check, so this is independent of
the separator character-class handling.
Adds a regression case (290200+311B) that was wrongly accepted at score 1.0.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Change Description
validate_resultchecks the date with:The actual century is carried by the 7th character (the separator), which
strptimenever receives. So 29 Feb of a non-leap century is wrongly accepted:290200+311Bdenotes 29 February 1800 (+= the 1800s). 1800 is not a leap year (divisible by 100 but not 400), so that date does not exist — butstrptimevalidates it as 29 Feb 2000, which is a leap year.Fix
Resolve the century from the separator (
+→ 1800s;- Y X W V U→ 1900s;A B C D E F→ 2000s) and validate the full date. Unknown separators fall back to the previousstrptimecheck, so this change is independent of the separator character-class (it does not touch which separators are allowed).Checklist
Tests
Adds
290200+311B(expected: not detected) — it fails before the fix (was accepted at 1.0). Valid codes such as131052-308Tare unchanged.