Fix TH TNIN regex rejecting valid province codes 22, 52 and 58#2107
Open
jichaowang02-lang wants to merge 1 commit into
Open
Fix TH TNIN regex rejecting valid province codes 22, 52 and 58#2107jichaowang02-lang wants to merge 1 commit into
jichaowang02-lang wants to merge 1 commit into
Conversation
The TNIN pattern excludes province codes (digits N2N3) that are not real Thai provinces, but the shared character class `[25][0134567]` is over-narrow: it drops N3=2 and N3=8 for *both* N2=2 and N2=5. Per the recognizer's own docstring, only 28, 29 (for N2=2) and 59 (for N2=5) should be excluded, so the class wrongly rejected the valid province codes 22 (Chanthaburi), 52 (Lampang) and 58 (Mae Hong Son). IDs with those codes never matched the pattern, so a genuinely valid TNIN (correct mod-11 checksum) was never detected. Split the shared class into `2[0-7]|5[0-8]`, which matches exactly the set of N2N3 combinations the docstring documents as valid. Verified exhaustively across all 90 N2N3 combinations: the regex now accepts every documented-valid code and still rejects all 13 forbidden ones. Adds regression cases for valid TNINs with province codes 22/52/58.
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 Thai National ID (TNIN) pattern excludes province codes (the 2nd–3rd digits,
N2N3) that aren't real Thai provinces. But the shared character class is over-narrow:[25][0134567]allowsN3 ∈ {0,1,3,4,5,6,7}for bothN2=2andN2=5, droppingN3=2andN3=8. But per the recognizer's own docstring, the only forbidden combinations are28, 29(forN2=2) and59(forN2=5). So the class wrongly rejects the valid province codes:225258An ID with one of these codes never matches the pattern, so a genuinely valid TNIN (correct mod-11 check digit) is never detected — a false negative.
Fix
Split the shared class into
2[0-7]|5[0-8], matching exactly the set ofN2N3combinations the docstring documents as valid.Checklist
Tests
1220000000007/1520000000004/1580000000004(provinces 22/52/58) — fail before the fix, pass after.N2N3combinations: the new regex accepts every documented-valid code and still rejects all 13 forbidden ones (the existing forbidden-combo tests still pass).