Fix ISSN output truncation when the issue code is nonzero

Поиск
Список
Период
Сортировка
Искать

Fix ISSN output truncation when the issue code is nonzero

От:
Jim Jones <jim.jones@uni-muenster.de>
Дата:
Вложения:
Hi

As reported in [1], a 13-digit issn with a nonzero issue publication
code is currently displayed in its 8-digit short form, which drops that
code. Values that differ only in the issue code are therefore displayed
identically while comparing unequal:

== master ==

psql (20devel)
Type "help" for help.

postgres=# create extension isn;
CREATE EXTENSION
postgres=#  with j (v1,v2) as (
 values ('12345679'::issn, '9771234567898'::issn)
)
select v1,v2,v1=v2 from j;
    v1     |    v2     | ?column?
-----------+-----------+----------
 1234-5679 | 1234-5679 | f
(1 row)


The attached patch adds a guard in ean2ISSN to keep the full issn in
case the given isn has an issue publication code, therefore avoiding
truncation.


== patched ==

psql (20devel)
Type "help" for help.

postgres=# create extension isn;
CREATE EXTENSION
postgres=#  with j (v1,v2) as (
 values ('12345679'::issn, '9771234567898'::issn)
)
select v1,v2,v1=v2 from j;
    v1     |        v2         | ?column?
-----------+-------------------+----------
 1234-5679 | 977-1234-567-89-8 | f
(1 row)


Best, Jim

1 -
https://www.postgresql.org/message-id/4e6c2fc9-5389-4958-a432-bb0ee5348ad0%40uni-muenster.de

Re: Fix ISSN output truncation when the issue code is nonzero

От:
Chao Li <li.evan.chao@gmail.com>
Дата:


> On Nov 18, 2026, at 16:26, Jim Jones  wrote:
> 
> Hi
> 
> As reported in [1], a 13-digit issn with a nonzero issue publication
> code is currently displayed in its 8-digit short form, which drops that
> code. Values that differ only in the issue code are therefore displayed
> identically while comparing unequal:
> 
> == master ==
> 
> psql (20devel)
> Type "help" for help.
> 
> postgres=# create extension isn;
> CREATE EXTENSION
> postgres=#  with j (v1,v2) as (
> values ('12345679'::issn, '9771234567898'::issn)
> )
> select v1,v2,v1=v2 from j;
>    v1     |    v2     | ?column?
> -----------+-----------+----------
> 1234-5679 | 1234-5679 | f
> (1 row)
> 
> 
> The attached patch adds a guard in ean2ISSN to keep the full issn in
> case the given isn has an issue publication code, therefore avoiding
> truncation.
> 
> 
> == patched ==
> 
> psql (20devel)
> Type "help" for help.
> 
> postgres=# create extension isn;
> CREATE EXTENSION
> postgres=#  with j (v1,v2) as (
> values ('12345679'::issn, '9771234567898'::issn)
> )
> select v1,v2,v1=v2 from j;
>    v1     |        v2         | ?column?
> -----------+-------------------+----------
> 1234-5679 | 977-1234-567-89-8 | f
> (1 row)
> 
> 
> Best, Jim
> 
> 1 -
> https://www.postgresql.org/message-id/4e6c2fc9-5389-4958-a432-bb0ee5348ad0%40uni-muenster.de

Thanks for the patch. I have a small comment:
```
+	/*
+	 * If the issue publication code is non-zero, we shouldn't
+	 * perform any truncation
+	 */
+	dehyphenate(digits, isn);
+	if (strncmp(digits + 10, "00", 2) != 0)
+		return;
```

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;
```

Best regards,
--
Chao Li (Evan)
HighGo Software Co., Ltd.
https://www.highgo.com/






Re: Fix ISSN output truncation when the issue code is nonzero

От:
Jim Jones <jim.jones@uni-muenster.de>
Дата:
Вложения:
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

Re: Fix ISSN output truncation when the issue code is nonzero

От:
Chao Li <li.evan.chao@gmail.com>
Дата:


> On Nov 19, 2026, at 15:12, Jim Jones  wrote:
> 
> 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
> 
> 

Thanks for updating the patch. V2 looks good to me.

Best regards,
--
Chao Li (Evan)
HighGo Software Co., Ltd.
https://www.highgo.com/






FAQ