From ceb76f28d323b4cb3e9498c2ea128f6604480321 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andr=C3=A9=20Kallehauge?= <3846700+kallehauge@users.noreply.github.com> Date: Mon, 12 Oct 2026 14:08:14 +0200 Subject: [PATCH 1/3] fix(bg/vat): accept 9-digit numbers whatever their first digit validate() refused any number not starting with 0, 1, 2, 3 or 9 with InvalidFormat, before the check digit was looked at. python-stdnum's bg/vat has never had that rule, and registered numbers fall outside it: BG831137001 is valid in the EU VIES service and was rejected. --- src/bg/vat.spec.ts | 14 ++++++++++++++ src/bg/vat.ts | 4 ---- 2 files changed, 14 insertions(+), 4 deletions(-) diff --git a/src/bg/vat.spec.ts b/src/bg/vat.spec.ts index 4d5d34fd..c3015dcc 100644 --- a/src/bg/vat.spec.ts +++ b/src/bg/vat.spec.ts @@ -31,4 +31,18 @@ describe('bg/vat', () => { expect(result.error).toBeInstanceOf(InvalidChecksum); }); + + // A registered company number (confirmed valid in the EU VIES service). The + // first digit is not restricted: python-stdnum's bg/vat has no such rule. + it('validate:BG 831137001', () => { + const result = validate('BG 831137001'); + + expect(result.isValid && result.compact).toEqual('831137001'); + }); + + it('validate:BG 831137002', () => { + const result = validate('BG 831137002'); + + expect(result.error).toBeInstanceOf(InvalidChecksum); + }); }); diff --git a/src/bg/vat.ts b/src/bg/vat.ts index 0da3c8f3..84e334ed 100644 --- a/src/bg/vat.ts +++ b/src/bg/vat.ts @@ -91,10 +91,6 @@ const impl: Validator = { return { isValid: false, error: new exceptions.InvalidFormat() }; } - if (!['0', '1', '2', '3', '9'].includes(value[0])) { - return { isValid: false, error: new exceptions.InvalidFormat() }; - } - if (value.length === 9) { if (!checkLegal(value)) { return { isValid: false, error: new exceptions.InvalidChecksum() }; From 0c7e324b3c83109ef58df709e6ba54b8423ac602 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andr=C3=A9=20Kallehauge?= <3846700+kallehauge@users.noreply.github.com> Date: Mon, 12 Oct 2026 14:18:40 +0200 Subject: [PATCH 2/3] test(bg/vat): use Vivacom's VAT number as the example BG831642181 belongs to Vivacom Bulgaria, one of the country's largest telecom operators, and is valid in the EU VIES service. It starts with 8, so it shows the same rejection with a well-known company. --- src/bg/vat.spec.ts | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/src/bg/vat.spec.ts b/src/bg/vat.spec.ts index c3015dcc..77eb547f 100644 --- a/src/bg/vat.spec.ts +++ b/src/bg/vat.spec.ts @@ -32,16 +32,16 @@ describe('bg/vat', () => { expect(result.error).toBeInstanceOf(InvalidChecksum); }); - // A registered company number (confirmed valid in the EU VIES service). The - // first digit is not restricted: python-stdnum's bg/vat has no such rule. - it('validate:BG 831137001', () => { - const result = validate('BG 831137001'); + // Vivacom Bulgaria's VAT number (valid in the EU VIES service). The first + // digit is not restricted: python-stdnum's bg/vat has no such rule. + it('validate:BG 831642181', () => { + const result = validate('BG 831642181'); - expect(result.isValid && result.compact).toEqual('831137001'); + expect(result.isValid && result.compact).toEqual('831642181'); }); - it('validate:BG 831137002', () => { - const result = validate('BG 831137002'); + it('validate:BG 831642182', () => { + const result = validate('BG 831642182'); expect(result.error).toBeInstanceOf(InvalidChecksum); }); From b51e1b0522489bb448e0fabccd6d813e1211660a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andr=C3=A9=20Kallehauge?= <3846700+kallehauge@users.noreply.github.com> Date: Mon, 12 Oct 2026 14:24:23 +0200 Subject: [PATCH 3/3] test(bg/vat): describe the registered number by its rule, not its owner --- src/bg/vat.spec.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/bg/vat.spec.ts b/src/bg/vat.spec.ts index 77eb547f..2ba7e58e 100644 --- a/src/bg/vat.spec.ts +++ b/src/bg/vat.spec.ts @@ -32,8 +32,8 @@ describe('bg/vat', () => { expect(result.error).toBeInstanceOf(InvalidChecksum); }); - // Vivacom Bulgaria's VAT number (valid in the EU VIES service). The first - // digit is not restricted: python-stdnum's bg/vat has no such rule. + // A registered VAT number starting with 8. The first digit is not + // restricted: python-stdnum's bg/vat has no such rule. it('validate:BG 831642181', () => { const result = validate('BG 831642181');