From 2150149ad1f706a17d2e454334d42211a2daa5a3 Mon Sep 17 00:00:00 2001 From: a3ylf Date: Mon, 7 Sep 2026 19:43:51 -0300 Subject: [PATCH 1/2] fix(isISBN): accept empty options when checking both versions --- src/lib/isISBN.js | 5 +++-- test/validators/isISBN.test.js | 23 +++++++++++++++++++++++ 2 files changed, 26 insertions(+), 2 deletions(-) diff --git a/src/lib/isISBN.js b/src/lib/isISBN.js index 4499c59a0..882d86261 100644 --- a/src/lib/isISBN.js +++ b/src/lib/isISBN.js @@ -9,12 +9,13 @@ export default function isISBN(isbn, options) { // For backwards compatibility: // isISBN(str [, version]), i.e. `options` could be used as argument for the legacy `version` - const version = String(options?.version || options); + let version = typeof options === 'object' ? options?.version : options; - if (!(options?.version || options)) { + if (!version) { return isISBN(isbn, { version: 10 }) || isISBN(isbn, { version: 13 }); } + version = String(version); const sanitizedIsbn = isbn.replace(/[\s-]+/g, ''); let checksum = 0; diff --git a/test/validators/isISBN.test.js b/test/validators/isISBN.test.js index 99fb2e014..b60a7d1e6 100644 --- a/test/validators/isISBN.test.js +++ b/test/validators/isISBN.test.js @@ -53,6 +53,29 @@ describe('isISBN', () => { }); }); + [ + { description: 'empty options', options: {} }, + { description: 'an undefined version', options: { version: undefined } }, + { description: 'a null version', options: { version: null } }, + ].forEach(({ description, options }) => { + it(`should validate both ISBN versions with ${description}`, () => { + test({ + validator: 'isISBN', + args: [options], + valid: [ + '340101319X', + '9784873113685', + ], + invalid: [ + '3423214121', + '9783836221190', + 'foo', + '', + ], + }); + }); + }); + describe('(legacy syntax)', () => { it('should validate ISBNs', () => { test({ From 797b78e858d6a156651e623eff15da73e4564b35 Mon Sep 17 00:00:00 2001 From: a3ylf Date: Mon, 7 Sep 2026 19:46:38 -0300 Subject: [PATCH 2/2] test(isISBN): cover null options compatibility --- test/validators/isISBN.test.js | 1 + 1 file changed, 1 insertion(+) diff --git a/test/validators/isISBN.test.js b/test/validators/isISBN.test.js index b60a7d1e6..f4005ff6a 100644 --- a/test/validators/isISBN.test.js +++ b/test/validators/isISBN.test.js @@ -54,6 +54,7 @@ describe('isISBN', () => { }); [ + { description: 'null options', options: null }, { description: 'empty options', options: {} }, { description: 'an undefined version', options: { version: undefined } }, { description: 'a null version', options: { version: null } },