From ef8a8b65fb411f7d301f35a2d254aec11336e24f Mon Sep 17 00:00:00 2001 From: Joshua Ramon Enslin Date: Wed, 15 Jul 2026 09:41:21 +0200 Subject: [PATCH] Fix bug where BNF IDs where validated too easily --- src/enums/MDNodaRepository.php | 2 +- tests/MDNodaRepositoryTest.php | 32 +++++++++++++++++++++++++++++++- 2 files changed, 32 insertions(+), 2 deletions(-) diff --git a/src/enums/MDNodaRepository.php b/src/enums/MDNodaRepository.php index 5245ec6..bf50527 100644 --- a/src/enums/MDNodaRepository.php +++ b/src/enums/MDNodaRepository.php @@ -782,7 +782,7 @@ enum MDNodaRepository implements MDValueEnumInterface, JsonSerializable { } else $id = self::validateNumericId($id, ["https://catalogue.bnf.fr/ark:/12148/cb"]); - if ($id === false) { + if ($id === false || strlen($id) < 6) { return false; } diff --git a/tests/MDNodaRepositoryTest.php b/tests/MDNodaRepositoryTest.php index ae608e8..e35a6f6 100644 --- a/tests/MDNodaRepositoryTest.php +++ b/tests/MDNodaRepositoryTest.php @@ -112,7 +112,9 @@ final class MDNodaRepositoryTest extends TestCase { */ public static function bnfIdForValidationProvider():Generator { - yield "Broken input / duplicate https" => [false, "https://catalogue.bnf.fr/ark:/12148/cbhttps://catalogue.bnf.fr/ark:/12148/cbhttps://catalogue.bnf.fr/ark:/12148/cb104183522"]; + yield "Working but duplicate https" => ["104183522", "https://catalogue.bnf.fr/ark:/12148/cbhttps://catalogue.bnf.fr/ark:/12148/cbhttps://catalogue.bnf.fr/ark:/12148/cb104183522"]; + yield "Broken input / 'X'" => [false, "X"]; + yield "Broken input / GND link" => [false, "https://d-nb.info/gnd/11858815X"]; } @@ -140,6 +142,21 @@ final class MDNodaRepositoryTest extends TestCase { } + /** + * Ensure validating references to the BNF. + * + * @param string|false $expected Expected output. + * @param string $inputString Input string. + * + * @return void + */ + #[DataProvider('bnfIdForValidationProvider')] + public function testBnfIdValidation(string|false $expected, string $inputString):void { + + self::assertEquals($expected, MDNodaRepository::bnf->validateId($inputString)); + + } + /** * Ensure validating references to the GND / Gemeinsame Normdatei works. * @@ -529,4 +546,17 @@ final class MDNodaRepositoryTest extends TestCase { self::assertNotEmpty(MDNodaRepository::caseNames()); } + + /** + * Tests conversion of already validated and set up entries to strings, GND version. + * + * @return void + */ + public function testConversionWorksGnd():void { + + $entry = MDNodaRepository::fromUrl("https://d-nb.info/gnd/11858815X"); + + self::assertEquals("gnd", $entry->toDbName()); + + } }