Fix bug where BNF IDs where validated too easily

This commit is contained in:
2026-07-15 09:41:21 +02:00
parent ce2f60d79d
commit ef8a8b65fb
2 changed files with 32 additions and 2 deletions
+1 -1
View File
@@ -782,7 +782,7 @@ enum MDNodaRepository implements MDValueEnumInterface, JsonSerializable {
} }
else $id = self::validateNumericId($id, ["https://catalogue.bnf.fr/ark:/12148/cb"]); else $id = self::validateNumericId($id, ["https://catalogue.bnf.fr/ark:/12148/cb"]);
if ($id === false) { if ($id === false || strlen($id) < 6) {
return false; return false;
} }
+31 -1
View File
@@ -112,7 +112,9 @@ final class MDNodaRepositoryTest extends TestCase {
*/ */
public static function bnfIdForValidationProvider():Generator { 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. * Ensure validating references to the GND / Gemeinsame Normdatei works.
* *
@@ -529,4 +546,17 @@ final class MDNodaRepositoryTest extends TestCase {
self::assertNotEmpty(MDNodaRepository::caseNames()); 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());
}
} }