1
0
mirror of https://github.com/postgres/postgres.git synced 2025-07-30 11:03:19 +03:00

Fix output of ISBN-13 numbers beginning with 979.

An EAN beginning with 979 (but not 9790 - those are ISMN's) are accepted
as ISBN numbers, but they cannot be represented in the old, 10-digit ISBN
format. They must be output in the new 13-digit ISBN-13 format. We printed
out an incorrect value for those.

Also add a regression test, to test this and some other basic functionality
of the module.

Patch by Fabien Coelho. This fixes bug #13442, reported by B.Z. Backpatch
to 9.1, where we started to recognize ISBN-13 numbers.
This commit is contained in:
Heikki Linnakangas
2015-08-02 22:12:33 +03:00
parent d73d14c271
commit cb3384a0cb
4 changed files with 345 additions and 10 deletions

View File

@ -443,16 +443,23 @@ ean2ISBN(char *isn)
char *aux;
unsigned check;
/* the number should come in this format: 978-0-000-00000-0 */
/* Strip the first part and calculate the new check digit */
hyphenate(isn, isn + 4, NULL, NULL);
check = weight_checkdig(isn, 10);
aux = strchr(isn, '\0');
while (!isdigit((unsigned char) *--aux));
if (check == 10)
*aux = 'X';
else
*aux = check + '0';
/*
* The number should come in this format: 978-0-000-00000-0
* or may be an ISBN-13 number, 979-..., which does not have a short
* representation. Do the short output version if possible.
*/
if (strncmp("978-", isn, 4) == 0)
{
/* Strip the first part and calculate the new check digit */
hyphenate(isn, isn + 4, NULL, NULL);
check = weight_checkdig(isn, 10);
aux = strchr(isn, '\0');
while (!isdigit((unsigned char) *--aux));
if (check == 10)
*aux = 'X';
else
*aux = check + '0';
}
}
static inline void