From fcce2a8e22389af1340fa9966edf0fe13a8d3481 Mon Sep 17 00:00:00 2001 From: Matthew Edmondson Date: Sun, 18 Oct 2026 06:27:25 +0000 Subject: [PATCH] Reject ISMNs (979-0) as ISBN-13s 979-0 is the International Standard Music Number range for printed music, not an ISBN range, and an ISMN carries a valid EAN-13 check digit, so it passed as an Isbn on its 979 prefix alone. Fixes ktsu-dev/Semantics#455 Co-Authored-By: Claude Opus 5.5 Claude-Session: https://claude.ai/code/session_01BT7W7buDP2wr6DWYZ2xKeQ --- .../IsIsbnAttribute.cs | 11 +++++++++-- Semantics.Strings.Identifiers/Isbn.cs | 4 ++-- Semantics.Strings.Identifiers/README.md | 2 +- Semantics.Test/Identifiers/IsbnTests.cs | 18 ++++++++++++++++++ 4 files changed, 30 insertions(+), 5 deletions(-) diff --git a/Semantics.Strings.Identifiers/IsIsbnAttribute.cs b/Semantics.Strings.Identifiers/IsIsbnAttribute.cs index 02acbf5c..fa91abd5 100644 --- a/Semantics.Strings.Identifiers/IsIsbnAttribute.cs +++ b/Semantics.Strings.Identifiers/IsIsbnAttribute.cs @@ -8,8 +8,9 @@ namespace ktsu.Semantics.Strings.Identifiers; /// /// Validates that the string is an ISBN-10 (weighted mod-11, final digit may be X) or an ISBN-13 -/// (mod-10, with the 978 or 979 Bookland prefix), evaluated on the separator-stripped -/// value. Registration-group and publisher ranges are not validated. +/// (mod-10, with the 978 or 979 Bookland prefix, excluding 9790, which is the ISMN +/// range for printed music), evaluated on the separator-stripped value. Registration-group and +/// publisher ranges are not validated. /// [AttributeUsage(AttributeTargets.Class, AllowMultiple = false, Inherited = true)] public sealed class IsIsbnAttribute : NativeSemanticStringValidationAttribute @@ -69,6 +70,12 @@ private static bool IsValidIsbn13(string s) return false; } + // 979-0 is not an ISBN range: it is the ISMN, which numbers printed music. + if (s.StartsWith("9790", StringComparison.Ordinal)) + { + return false; + } + int sum = 0; for (int i = 0; i < 13; i++) { diff --git a/Semantics.Strings.Identifiers/Isbn.cs b/Semantics.Strings.Identifiers/Isbn.cs index 81c00b01..a7d7058a 100644 --- a/Semantics.Strings.Identifiers/Isbn.cs +++ b/Semantics.Strings.Identifiers/Isbn.cs @@ -8,8 +8,8 @@ namespace ktsu.Semantics.Strings.Identifiers; /// An International Standard Book Number in ISBN-10 or ISBN-13 form, e.g. 0306406152 or /// 9780306406157. Hyphens and spaces are stripped and the value is uppercased (for the ISBN-10 /// X check digit) on creation. The check digit is validated, and an ISBN-13 must start with -/// the 978 or 979 Bookland prefix; registration-group and publisher ranges are not -/// validated. +/// the 978 or 979 Bookland prefix, but not 9790, which is the ISMN range for printed +/// music; registration-group and publisher ranges are not validated. /// [IsIsbn] public sealed record Isbn : SemanticString diff --git a/Semantics.Strings.Identifiers/README.md b/Semantics.Strings.Identifiers/README.md index 28a0c8e5..81df84b8 100644 --- a/Semantics.Strings.Identifiers/README.md +++ b/Semantics.Strings.Identifiers/README.md @@ -87,7 +87,7 @@ Each type is a `sealed record` deriving from `SemanticString`. None declare t | `Uuid` | Trim, strip wrapping `{}` / `()`, lowercase | Canonical 8-4-4-4-12 hex (RFC 4122 layout) | Any variant/version accepted, including the nil UUID. Not version-checked. | | `Ulid` | Trim, uppercase | 26 Crockford base32 chars, first char `0`-`7` | Timestamp is not otherwise decoded. | | `Iban` | Strip spaces, uppercase | Length 15-34, country/check prefix, ISO 7064 mod-97-10 checksum | Country-specific BBAN structure is not enforced. | -| `Isbn` | Strip `-` and spaces, uppercase | ISBN-10 (weighted mod-11, `X` allowed) or ISBN-13 (`978`/`979` prefix, mod-10) | Registration-group/publisher ranges are not validated. | +| `Isbn` | Strip `-` and spaces, uppercase | ISBN-10 (weighted mod-11, `X` allowed) or ISBN-13 (`978`/`979` prefix but not the `9790` ISMN range, mod-10) | Registration-group/publisher ranges are not validated. | | `CreditCardNumber` | Strip spaces and hyphens | 13-19 digits, Luhn (mod-10) checksum | Luhn only. No issuer/network detection, no PCI guarantee. The value is sensitive, do not log it. | | `JwtToken` | None (stored verbatim, case-sensitive) | Three `.`-separated segments in the unpadded base64url alphabet (no whitespace, `=`, `+` or `/`), non-empty header and payload that decode to UTF-8 text delimited as `{ ... }` | Structural only: the header and payload bodies are not parsed, so malformed JSON between the braces is accepted. Signature is not decoded or verified. `alg`, claims, and expiry are not inspected. | diff --git a/Semantics.Test/Identifiers/IsbnTests.cs b/Semantics.Test/Identifiers/IsbnTests.cs index cc044222..28e134b5 100644 --- a/Semantics.Test/Identifiers/IsbnTests.cs +++ b/Semantics.Test/Identifiers/IsbnTests.cs @@ -56,6 +56,24 @@ public void Create_Ean13OutsideBooklandRange_Throws(string ean13) Assert.ThrowsExactly(() => Isbn.Create(ean13)); } + [TestMethod] + [DataRow("979-0-2600-0043-8")] + [DataRow("9790060115615")] + public void Create_Ismn_Throws(string ismn) + { + Assert.ThrowsExactly(() => Isbn.Create(ismn)); + } + + [TestMethod] + [DataRow("979-0-2600-0043-8")] + [DataRow("9790060115615")] + public void TryCreate_Ismn_ReturnsFalse(string ismn) + { + bool created = Isbn.TryCreate(ismn, out Isbn? result); + Assert.IsFalse(created); + Assert.IsNull(result); + } + [TestMethod] public void TryCreate_Ean13OutsideBooklandRange_ReturnsFalse() {