Skip to content

fix: ISSN checksum returns 11 instead of 0 when weighted sum is divisible by 11#262

Merged
WhyNotHugo merged 1 commit into
WhyNotHugo:mainfrom
gaoflow:fix/issn-checksum-zero
Jun 25, 2026
Merged

fix: ISSN checksum returns 11 instead of 0 when weighted sum is divisible by 11#262
WhyNotHugo merged 1 commit into
WhyNotHugo:mainfrom
gaoflow:fix/issn-checksum-zero

Conversation

@gaoflow

@gaoflow gaoflow commented Jun 25, 2026

Copy link
Copy Markdown
Contributor

Summary

Fixes #238.

The _calculate_checksum method in InternationalStandardSerialNumber was missing a trailing % 11. When the weighted digit sum is exactly divisible by 11, the formula computes 11 - 0 = 11 — an invalid two-digit value — instead of (11 - 0) % 11 = 0.

Before:

tmp = (
    11
    - sum(x * int(y) for x, y in enumerate(reversed(self.issn[:7]), start=2))
    % 11
)

After:

tmp = (
    11
    - sum(x * int(y) for x, y in enumerate(reversed(self.issn[:7]), start=2))
    % 11
) % 11

Minimal reproduction:

from barcode import ISSN
print(ISSN("6727893").issn)  # was "672789311", now correctly "67278930"

Two regression tests added to tests/test_checksums.py: one for the zero-checksum case and one confirming the X checksum case still works.

This pull request was prepared with the assistance of AI, under my direction and review.

…ible by 11

The `_calculate_checksum` method in `InternationalStandardSerialNumber`
was missing a final `% 11`, causing it to return 11 (an invalid
two-digit value) instead of 0 when the weighted digit sum happened to
be exactly divisible by 11.

Fixes WhyNotHugo#238.
@WhyNotHugo

Copy link
Copy Markdown
Owner

Sounds correct to me.

@WhyNotHugo WhyNotHugo merged commit bc97480 into WhyNotHugo:main Jun 25, 2026
11 of 12 checks passed
@WhyNotHugo

Copy link
Copy Markdown
Owner

Thanks!

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.

Wrong checksum for ISSN

2 participants