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 crash when using EAN without checksums #98

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 4 additions & 7 deletions barcode/ean.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,8 @@ class EuropeanArticleNumber13(Barcode):
digits = 12

def __init__(self, ean, writer=None, no_checksum=False):
self.digits = 13 if no_checksum else 12

ean = ean[: self.digits]
if not ean.isdigit():
raise IllegalCharacterError("EAN code can only contain numbers.")
Expand All @@ -54,14 +56,9 @@ def __init__(self, ean, writer=None, no_checksum=False):
len(ean),
)
)
self.ean = ean
# If no checksum

if no_checksum:
# Add a thirteen char if given in parameter,
# otherwise pad with zero
self.ean = "{}{}".format(
ean, ean[self.digits] if len(ean) > self.digits else 0
)
self.ean = ean
Copy link
Owner Author

Choose a reason for hiding this comment

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

The original ean value is lost due to the ean = ean[: self.digits] statement above.

This won't work.

else:
self.ean = "{}{}".format(ean, self.calculate_checksum())
self.writer = writer or Barcode.default_writer()
Expand Down