Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: French VAT checksum failing for leading zero #118

Merged
merged 1 commit into from
Jun 5, 2024

Conversation

RamonBalthazar
Copy link
Contributor

@RamonBalthazar RamonBalthazar commented Jun 3, 2024

This is a valid French VAT number: 04813837531.
The checksum bit is: 04.
The sum is correctly being calculated as 4, but validation fails when comparing "4" with "04".

As a solution we compare numbers instead of strings.

@@ -80,8 +80,7 @@ const impl: Validator = {
if (strings.isdigits(check)) {
const sum = (12 + 3 * (parseInt(back, 10) % 97)) % 97;

const stringSum = String(sum).padStart(2, '0');
if (stringSum !== check) {
if (sum !== parseInt(check, 10)) {
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would you mind adding a test case that handles this fix.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sure!

@RamonBalthazar
Copy link
Contributor Author

@koblas Added test cases :)

@koblas koblas merged commit 90768b7 into koblas:main Jun 5, 2024
2 checks passed
@RamonBalthazar RamonBalthazar deleted the fix-french-checksum-zero-pad branch June 12, 2024 11:35
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.

2 participants