-
Notifications
You must be signed in to change notification settings - Fork 33
fix(ro): correct checksum alignment for 10-digit CUI numbers #145
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -57,7 +57,10 @@ const impl: Validator = { | |
| return { isValid: false, error: new exceptions.InvalidFormat() }; | ||
| } | ||
|
|
||
| const [front, check] = strings.splitAt(value.padStart(9, '0'), -1); | ||
| // FIX: Pad to 10 total digits. | ||
| // This ensures that 'front' is always exactly 9 digits, | ||
| // perfectly matching the 9 weights provided. | ||
| const [front, check] = strings.splitAt(value.padStart(10, '0'), -1); | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The Romanian CUI validation logic is fundamentally flawed and remains broken despite the alignment fix. The checksum calculation on line 72 ( This creates a significant security bypass where the validator incorrectly marks any CUI ending in '0' as valid (provided it meets length and digit requirements) and rejects almost all valid CUIs that do not end in '0'. To correctly implement the Romanian CUI algorithm, the logic should be: |
||
|
|
||
| const sum = | ||
| 10 * | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
While the comment is helpful, using prefixes like
FIX:can be mistaken for temporary code markers (likeTODOorFIXME) and may cause confusion for future maintainers. For long-term clarity, it's better to have a comment that explains the logic's purpose. I suggest rephrasing to focus on why the padding is necessary.