fix(ar/cbu): accept valid CBUs whose check digit is 0 - #167
Merged
Conversation
`10 - weightedSum(...)` yields 10 (not 0) when the weighted sum is 0, and `String(10)` is "10", which never equals a single-character check digit "0". So any valid CBU whose bank block or account block has a check digit of 0 was wrongly rejected with InvalidChecksum. Wrap the result modulo 10, matching what the sibling mx/clabe validator already does: `(10 - weightedSum(...)) % 10`. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Contributor
|
Caution The consumer version of Gemini Code Assist on GitHub has been sunset. All code review activity has officially ceased. |
koblas
approved these changes
Aug 1, 2026
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.
Problem
AR.cburejects valid CBUs whenever either of the two check digits is0.Root cause
In
src/ar/cbu.tsthe check digits are computed as:weightedSum(..., { modulus: 10 })already returns a value in[0, 9], so10 - thatis in
[1, 10]. WhenweightedSumreturns0,10 - 0 === 10andString(10)is"10", which can never equal the single-character check digitc1/c2("0"). Any CBUwhose bank block or account block has a check digit of
0is therefore rejected.Worked example for
0720429088000002339140:0720429,c1 = "0",weightedSum(front) = 0→s1 = "10"(should be"0")8800000233914,c2 = "0",weightedSum(back) = 0→s2 = "10"(should be"0")Fix
Wrap the result modulo 10 — the same thing the sibling
src/mx/clabe.tsvalidatoralready does (
(10 - weightedSum(...)) % 10), so this just bringsar/cbuin line with it.Tests
Added three cases to
src/ar/cbu.spec.ts:0720429088000002339140— both check digits0→ now valid0000000000000000000000— both check digits0→ now valid0720429088000002339141— tampered → stillInvalidChecksumFull suite passes (
npx jest), lint and prettier are clean.