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

EAN validator is too picky #331

Closed
OdyX opened this issue Apr 16, 2018 · 0 comments
Closed

EAN validator is too picky #331

OdyX opened this issue Apr 16, 2018 · 0 comments

Comments

@OdyX
Copy link
Contributor

OdyX commented Apr 16, 2018

In the context of the https://github.com/defivelo/db project, I have two EAN numbers which validate on https://www.getnewidentity.com/validate-ean.php but are not considered valid by from localflavor.generic.validators.EANValidator:

>>> from localflavor.generic.validators import EANValidator
>>> v = EANValidator()
>>> v('7567554394380')
Traceback (most recent call last):
  File "<console>", line 1, in <module>
  File "…/env/local/lib/python2.7/site-packages/localflavor/generic/validators.py", line 272, in __call__
    raise ValidationError(self.message, code='invalid')
ValidationError: [u'Not a valid EAN code.']
>>> >>> v2("756.4334.3999.00")
Traceback (most recent call last):
  File "<console>", line 1, in <module>
  File "…/env/local/lib/python2.7/site-packages/localflavor/generic/validators.py", line 272, in __call__
    raise ValidationError(self.message, code='invalid')
ValidationError: [u'Not a valid EAN code.']

These don't work for instance:

  • 756.7554.3943.80
  • 756.4334.3999.00

As mentionned in the pull request, this is an issue about the calculated_checksum which can be 10, which cannot be compared to a single-digit.

OdyX added a commit to defivelo/django-localflavor that referenced this issue Apr 16, 2018
It was buggy because:
* `calculated_checksum % 10` could be `0` if `calculated_checksum` is a multiple of 10
* `10 - 0 = 10`
* `10` cannot be validly string-compared to a single-digit

Fixes: django#331
benkonrath pushed a commit that referenced this issue Apr 16, 2018
It was buggy because:
* `calculated_checksum % 10` could be `0` if `calculated_checksum` is a multiple of 10
* `10 - 0 = 10`
* `10` cannot be validly string-compared to a single-digit

Fixes: #331
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

No branches or pull requests

1 participant