From 887a13e34430adb6f651c4b4f78d23e79faedda0 Mon Sep 17 00:00:00 2001 From: Shayan Zarei Date: Wed, 25 Feb 2026 17:41:42 +0100 Subject: [PATCH] fix(ro): correct padding logic for 10-digit CUI validation --- src/ro/cui.spec.ts | 13 +++++++++++++ src/ro/cui.ts | 5 ++++- 2 files changed, 17 insertions(+), 1 deletion(-) diff --git a/src/ro/cui.spec.ts b/src/ro/cui.spec.ts index 632f43a8..df993786 100644 --- a/src/ro/cui.spec.ts +++ b/src/ro/cui.spec.ts @@ -8,6 +8,12 @@ describe('ro/cui', () => { expect(result).toEqual('185 472 90'); }); + it('validate:18547290 (8 digits, padded to 10 for checksum)', () => { + const result = validate('18547290'); + + expect(result.isValid).toBe(true); + }); + it('validate:185 472 90', () => { const result = validate('185 472 90'); @@ -25,4 +31,11 @@ describe('ro/cui', () => { expect(result.error).toBeInstanceOf(InvalidChecksum); }); + + it('validate:18547291 (8 digits, invalid checksum after padding)', () => { + const result = validate('18547291'); + + expect(result.isValid).toBe(false); + expect(result.error).toBeInstanceOf(InvalidChecksum); + }); }); diff --git a/src/ro/cui.ts b/src/ro/cui.ts index 1de45097..e285831d 100644 --- a/src/ro/cui.ts +++ b/src/ro/cui.ts @@ -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); const sum = 10 *