Fix NG NIN rejecting valid numbers with a leading zero#2106
Open
jichaowang02-lang wants to merge 1 commit into
Open
Fix NG NIN rejecting valid numbers with a leading zero#2106jichaowang02-lang wants to merge 1 commit into
jichaowang02-lang wants to merge 1 commit into
Conversation
NgNinRecognizer validated the Verhoeff checksum on `int(value)`, which drops a leading zero and shortens the digit string. An 11-digit NIN beginning with `0` (e.g. `00000000005`, a genuinely valid Verhoeff number) was therefore checked on only 10 digits and wrongly rejected — a false negative for ~10% of the NIN space. Pass the digit string straight to the Verhoeff check instead of `int(value)`, so all 11 digits are validated. Non-leading-zero NINs are unaffected. Adds an analyze-level case for a leading-zero NIN (fails before the fix) and a direct Verhoeff regression; also corrects the prior all-zeros unit test, which passed `int(0)` (a single "0", which is valid) rather than the 11-digit all-zero string (which is not a valid Verhoeff number).
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
NgNinRecognizervalidated the Verhoeff checksum onint(value):int("00000000005")→5, and_is_verhoeff_numberthen runsstr(...)on it, so the checksum is computed on a shortened digit string. An 11‑digit NIN that begins with0— e.g.00000000005, a genuinely valid Verhoeff number — is checked on fewer than 11 digits and wrongly rejected (a false negative for the ~10% of the NIN space that starts with0). The NIN spec places no restriction forbidding a leading zero.Fix
Pass the digit string to the Verhoeff check instead of
int(value), so all 11 digits are validated. Non‑leading‑zero NINs are unaffected.Checklist
Tests
VALID_NIN_LEADING_ZERO) — fails before the fix, passes after.int(0)— a single"0", which is a valid Verhoeff number — rather than the 11-digit all-zero string (which is not valid), so it never exercised the all-zero NIN.