vatin: reject a duplicated country code prefix (#420)#500
Open
CedricConday wants to merge 1 commit into
Open
Conversation
vatin.validate() stripped the leading country code itself and then passed the remainder to the country module, which strips its own optional country code prefix again. For a doubled prefix such as 'BE BE 0308.357.159' both strips fired, leaving a valid national number, so the VATIN validated even though stdnum.eu.vat correctly rejects it. Validate the full number with the country module (which strips its own prefix once), mirroring stdnum.eu.vat, and only fall back to stripping the country code for modules that do not recognise it - guarding that fallback so a doubled prefix is not stripped a second time. Closes arthurdejong#420.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Closes #420
vatin.is_valid()accepts a VAT number with a doubled country code, whilestdnum.eu.vatcorrectly rejects it:Cause
vatin.validate()stripped the leading country code itself (module.validate(number[2:])) and then handed the remainder to the country module, which strips its own optional country-code prefix again. ForBE BE 0308.357.159both strips fired, leaving the valid national number0308357159. Countries whose module doesn't strip a prefix (e.g.BR) weren't affected, which is why it reproduced for BE/NL but not MX.Fix
Validate the full number with the country module (it strips its own prefix exactly once), mirroring
stdnum.eu.vat. Only fall back to stripping the country code for modules that don't recognise it — and guard that fallback so a doubled prefix (even writtenBE BE …with whitespace) is not stripped a second time.Tests
Added doctests in
tests/test_vatin.doctestfor the doubled-prefix case (with and without whitespace). They fail onmasterand pass with the fix. The full test suite stays green (405 passed, 9 network-skipped), including the existing multi-country vatin doctests (FR/DE/BR/EL→GR/CHE/XI/EU).