python-barcode
python-barcode copied to clipboard
Unwanted behaviour of the no_checksum option for EuropeanArticleNumber13
If the no_checksum option is passed, A 13 digits code should be accepted as it is. At the moment, the last digit is replaced by a 0 and it cannot be otherwise:
digits = 12
ean = ean[:self.digits]
# Add a thirteen char if given in parameter,
# otherwise pad with zero
self.ean = '{0}{1}'.format( ean, ean[self.digits] if len(ean) > self.digits else 0)
len(ean) > self.digits is never going to happen
Bump. Looks like it is indeed does not work as intended.
>>> barcode.get('ean13')('1234567891234', no_checksum=True)
<EuropeanArticleNumber13('1234567891230')>
instead of 1234567891234.
Can you confirm if #98 fixes the issue for you?
If so, I'll add some tests and merge it in. Thanks!
I am too lazy to figure out how to build/install it :D
But yeah, looks correct.
Maybe adding some validation for the number of digits would be good.
Fix crash
hm, I did not have any crashes. :thinking: Just wrong last digit output like above.
hello, is this bug fixed? i tried python-barcode 0.14.0 on windows 10 py 3.9.0, the last digit/checksum can not be disabled
>>> import barcode
>>> barcode.get('ean13')('1234567891234', no_checksum=True)
<EuropeanArticleNumber13('1234567891230')>
>>>
>>> from barcode import EAN13
>>>
>>> EAN13("1234567891234").get_fullcode()
'1234567891231'
>>>
>>> EAN13("1234567891235").get_fullcode()
'1234567891231'
>>>
>>> EAN13("1234567891236").get_fullcode()
'1234567891231'
>>>
>>> EAN13("1234567891237").get_fullcode()
'1234567891231'
>>>
>>> EAN13("1234567891237").calculate_checksum()
2