Skip to content

fix(dk/cvr): reject numbers that start with 0 - #171

Open
kallehauge wants to merge 3 commits into
koblas:mainfrom
kallehauge:fix/dk-cvr-leading-zero
Open

kallehauge wants to merge 3 commits into
koblas:mainfrom
kallehauge:fix/dk-cvr-leading-zero

Conversation

@kallehauge

Copy link
Copy Markdown

Problem

dk/cvr accepts 00000000 as a valid CVR number:

stdnum.DK.cvr.validate('00000000');
// { isValid: true, compact: '00000000', isIndividual: false, isCompany: true }

Its modulus 11 sum is 0, so the check digit matches. 00000000 is a common placeholder in VAT-number fields, so it ends up treated as a real company number.

Fix

No CVR number starts with 0. python-stdnum's dk/cvr refuses those with InvalidFormat (stdnum/dk/cvr.py#L56):

if not isdigits(number) or number[0] == '0':
    raise InvalidFormat()

This PR adds the same check.

Input Before After
00000000 valid InvalidFormat
DK00000000 valid InvalidFormat
01000004 (passes modulus 11) valid InvalidFormat
24256790 (Novo Nordisk A/S) valid valid
13585628 valid valid

Tested

  • src/dk/cvr.spec.ts: 3 new cases that fail before the change and pass after it, plus 2 showing a real company's CVR still passes (Novo Nordisk A/S, valid in the EU VIES service and active in the Danish CVR register).
  • Full suite: TZ=UTC npx jest --runInBand passes, 200 suites / 1640 tests.
  • npm run lint passes.

No CVR number starts with 0, and python-stdnum's dk/cvr refuses them
with InvalidFormat. Without the check, 00000000 passes as a valid CVR
because its modulus 11 sum is 0, so a common placeholder value is
accepted as a real company number.
Novo Nordisk A/S (24256790), active in the Danish CVR register, with
and without the DK prefix.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant