From 7ef8021f2edb740e3dc82e6b3eab07c807551fe2 Mon Sep 17 00:00:00 2001 From: David Koblas Date: Tue, 4 Jul 2023 06:35:36 -0400 Subject: [PATCH] fix: added natural numbers for EC/RUC --- src/ec/ruc.spec.ts | 9 +++++++++ src/ec/ruc.ts | 7 ++++++- 2 files changed, 15 insertions(+), 1 deletion(-) diff --git a/src/ec/ruc.spec.ts b/src/ec/ruc.spec.ts index ff816e5b..c608fcd8 100644 --- a/src/ec/ruc.spec.ts +++ b/src/ec/ruc.spec.ts @@ -14,6 +14,15 @@ describe('ec/ruc', () => { expect(result.isValid && result.compact).toEqual('1792060346001'); }); + test.each(['0101016905001', '0962467429001', '1803557964001'])( + 'validate:%s', + value => { + const result = validate(value); + + expect(result.isValid).toEqual(true); + }, + ); + it('validate:1792060346-00', () => { const result = validate('1792060346-00'); diff --git a/src/ec/ruc.ts b/src/ec/ruc.ts index 4f260cb2..76e571c8 100644 --- a/src/ec/ruc.ts +++ b/src/ec/ruc.ts @@ -79,7 +79,12 @@ const impl: Validator = { modulus: 11, }) !== 0 ) { - return { isValid: false, error: new exceptions.InvalidChecksum() }; + // If it's not a public, try natural + if (end.endsWith('000')) { + return { isValid: false, error: new exceptions.InvalidComponent() }; + } + + return ci.validate(value.substring(0, 10)); } } else if (value[2] === '9') { // Juridical RUC