Hi Chao On 19/11/2026 01:24, Chao Li wrote: > While debugging this patch, I noticed that the input isn has already been > hyphenated, and ean2ISSN() is a local static function that is only called by > ean2string(). Actually, your new logic of returning directly relies on isn > being hyphenated. So I don't think we need to dehyphenate isn. Instead, we > can just compare: > ``` > if (strncmp(isn + 13, "00", 2) != 0) > return; > ```
Good catch! dehyphenate is indeed superfluous here. v2 attached removes the function call and the digits buffer. Thanks! Best, Jim
From 82a81febc99143174f05d70abdda3e527c642e51 Mon Sep 17 00:00:00 2001 From: Jim Jones <[email protected]> Date: Thu, 19 Nov 2026 08:06:11 +0100 Subject: [PATCH v2] Fix ISSN output truncation when the issue code is nonzero ISSN output always used the 8-digit short form, which drops the two-digit issue publication code of an ISSN-13. Values that differ only in that code were displayed identically while comparing unequal. Use the short form only when the code is 00. Author: Jim Jones <[email protected]> Reviewed-by: Jonah Shafran <[email protected]> Reviewed-by: Chao Li <[email protected]> --- contrib/isn/expected/isn.out | 9 +++++---- contrib/isn/isn.c | 7 +++++++ contrib/isn/sql/isn.sql | 3 ++- 3 files changed, 14 insertions(+), 5 deletions(-) diff --git a/contrib/isn/expected/isn.out b/contrib/isn/expected/isn.out index c533768d926..fa1759b55d1 100644 --- a/contrib/isn/expected/isn.out +++ b/contrib/isn/expected/isn.out @@ -105,10 +105,11 @@ SELECT '9790123456785'::ISMN13, (1 row) SELECT '9771234567003'::ISSN, - '12345679'::ISSN; - issn | issn ------------+----------- - 1234-5679 | 1234-5679 + '12345679'::ISSN, + '9771234567898'::ISSN; + issn | issn | issn +-----------+-----------+------------------- + 1234-5679 | 1234-5679 | 977-1234-567-89-8 (1 row) SELECT '9771234567003'::ISSN13, diff --git a/contrib/isn/isn.c b/contrib/isn/isn.c index a1d2f26158a..a8807d3d9ae 100644 --- a/contrib/isn/isn.c +++ b/contrib/isn/isn.c @@ -473,6 +473,13 @@ ean2ISSN(char *isn) { unsigned check; + /* + * If the issue publication code is non-zero, we shouldn't + * perform any truncation + */ + if (strncmp(isn + 13, "00", 2) != 0) + return; + /* the number should come in this format: 977-0000-000-00-0 */ /* Strip the first part, crop, and calculate the new check digit */ hyphenate(isn, isn + 4, NULL, NULL); diff --git a/contrib/isn/sql/isn.sql b/contrib/isn/sql/isn.sql index 043e5580b0d..270f5c38a22 100644 --- a/contrib/isn/sql/isn.sql +++ b/contrib/isn/sql/isn.sql @@ -48,7 +48,8 @@ SELECT '9790123456785'::ISMN13, 'M-1234-5678-5'::ISMN13; SELECT '9771234567003'::ISSN, - '12345679'::ISSN; + '12345679'::ISSN, + '9771234567898'::ISSN; SELECT '9771234567003'::ISSN13, '12345679'::ISSN13, -- 2.56.1
