Skip to content

[patch] Require the 978/979 Bookland prefix on an ISBN-13 - #407

Merged
matt-edmondson merged 1 commit into
mainfrom
fix/334-isbn13-bookland-prefix
Oct 9, 2026
Merged

matt-edmondson merged 1 commit into
mainfrom
fix/334-isbn13-bookland-prefix

Conversation

@matt-edmondson

Copy link
Copy Markdown
Contributor

Fixes #334

What was wrong

IsIsbnAttribute checked only an ISBN-13's mod-10 check digit. Every EAN-13 barcode passes that check, so Isbn.Create("4006381333931"), a non-book product code, validated as an ISBN.

Change (Semantics.Strings.Identifiers)

  • IsIsbnAttribute.IsValidIsbn13 rejects any value that doesn't start with 978 or 979, the Bookland range ISBNs are allocated from. It runs before the checksum.
  • ISBN-10 validation is unchanged.
  • The XML docs on IsIsbnAttribute and Isbn and the rules table in the package README now mention the prefix.

Release note: this tightens validation. An Isbn that was stored from a non-978/979 EAN-13 will now fail Create and TryCreate.

Tests (IsbnTests)

  • Create_Ean13OutsideBooklandRange_Throws: 4006381333931 (the issue's example), 5901234123457, and 9770317847001 (an ISSN-style 977 barcode). Each has a valid EAN-13 check digit and now throws ArgumentException.
  • TryCreate_Ean13OutsideBooklandRange_ReturnsFalse: TryCreate returns false with a null result.
  • Create_ValidIsbn13With979Prefix_Succeeds: 979-10-90636-07-1 still validates, so the 979 range keeps working.

Verification

  • With IsIsbnAttribute.cs reverted, the 4 out-of-range cases fail. With the fix, all 12 IsbnTests pass.
  • The full Semantics.Test suite passes on net10.0: 1485 passed, 0 failed, 8 skipped (the same 8 are skipped on main).
  • Semantics.Strings.Identifiers builds with the local Sonar analyzers (.sonarlint/sonar-local.props) with 0 warnings.

🤖 Generated with Claude Code

https://claude.ai/code/session_01LoEzLXruuTHCcJnXtVa49Z


Generated by Claude Code

IsIsbnAttribute only checked an ISBN-13's mod-10 check digit, which every
EAN-13 barcode passes, so Isbn.Create("4006381333931") accepted a non-book
product code. An ISBN-13 must now start with 978 or 979.

Fixes #334

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01LoEzLXruuTHCcJnXtVa49Z
@sonarqubecloud

sonarqubecloud Bot commented Oct 8, 2026

Copy link
Copy Markdown

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.

Isbn accepts any EAN-13 barcode: Isbn.Create("4006381333931") (a non-book product code) validates because the 978/979 prefix is never checked

2 participants