Fix FI HETU regex accepting illegal century separators#2108
Open
jichaowang02-lang wants to merge 1 commit into
Open
Fix FI HETU regex accepting illegal century separators#2108jichaowang02-lang wants to merge 1 commit into
jichaowang02-lang wants to merge 1 commit into
Conversation
The Finnish personal identity code pattern used the character class `[+-ABCDEFYXWVU]` for the century separator (the 7th character). Because the `-` sits between `+` and `A`, the regex engine reads `+-A` as a character *range* (U+002B..U+0041), which silently admits `, . / 0-9 : ; < = > ? @` as "separators". validate_result only re-checks the date and control character, never the separator, so an 11-char string with a junk separator but an otherwise-correct control digit (e.g. `131052/308T`) is wrongly accepted — a false positive. Per the DVV spec the separator must be exactly one of `+ - A B C D E F Y X W V U`. Move the `-` to the start of the class so it is a literal, in both the Medium and Very Weak patterns. Adds regression cases: `131052/308T`, `131052:308T`, `131052.308T` (valid date+control, illegal separator) are now rejected; the valid `131052-308T` is still detected.
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
The Finnish personal identity code (HETU) patterns use this class for the century separator (7th character):
Because
-sits between+(U+002B) andA(U+0041), the engine reads+-Aas a character range, which silently admits, . / 0-9 : ; < = > ? @as "separators".validate_resultonly re-checks the date and control character — never the separator — so an 11-character string with a junk separator but an otherwise-correct control digit is wrongly accepted:Per the DVV spec the separator must be exactly one of
+ - A B C D E F Y X W V U(+= 1800s;- Y X W V U= 1900s;A B C D E F= 2000s).Fix
Move the
-to the start of the class ([-+ABCDEFYXWVU]) so it is a literal, in both the Medium and Very Weak patterns.Checklist
Tests
New cases
131052/308T,131052:308T,131052.308T(valid date + control digit, illegal separator) are now rejected — they fail before the fix — while the valid131052-308Tis still detected.