Fix KidnummerValidator incorrectly accepting invalid KID numbers#76
Open
leifthorbjornsen wants to merge 1 commit intobekkopen:masterfrom
Open
Conversation
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.
Fixes a bug in
KidnummerValidator.isValid()where some invalid KID numbers were accepted.Examples:
The issue is in the mod11 check:
When the mod11 remainder is 1, there is no valid single digit that can serve as a checksum digit, so it returns
-instead. The bug was that the validator treated this as an automatic pass, without checking that the KID number actually ended with-. As a result, any KID that failed mod10 and happened to produce a mod11 remainder of 1 would be incorrectly accepted.The fix is to compare the calculated mod11 result directly with the last character of the KID:
This works for both digits and
-without special handling.1000005-still passes because mod11 returns-and the last character is-, while100030now correctly fails because mod11 returns-but the last character is0.Also added a test for the bug case: