Added additional variants of nomisma, iconclass IDs
This commit is contained in:
@@ -400,12 +400,23 @@ enum MDNodaRepository implements MDValueEnumInterface, JsonSerializable {
|
|||||||
private static function validateIconclassId(string $id):string|false {
|
private static function validateIconclassId(string $id):string|false {
|
||||||
|
|
||||||
if (filter_var($id, FILTER_VALIDATE_URL) !== false) {
|
if (filter_var($id, FILTER_VALIDATE_URL) !== false) {
|
||||||
$id = strtr($id, ['http://iconclass.org/rkd/' => '', 'http://iconclass.org/' => '', 'https://iconclass.org/' => '']);
|
$id = rtrim(strtr($id, [
|
||||||
|
'http://iconclass.org/rkd/' => '',
|
||||||
|
'http://iconclass.org/' => '',
|
||||||
|
'https://iconclass.org/' => '',
|
||||||
|
'http://www.iconclass.org/rkd/' => '',
|
||||||
|
'http://www.iconclass.org/' => '',
|
||||||
|
'https://www.iconclass.org/' => '',
|
||||||
|
]), '/');
|
||||||
}
|
}
|
||||||
$id = trim($id, "/");
|
$id = trim($id, "/");
|
||||||
|
|
||||||
if (!empty(trim($id, '0123456789abcdefghijklmnopqrstuvwxyz/ABCDEFGHIJKLMNOPQRSTUVWXYZ'))) {
|
if (!empty(trim($id, '0123456789abcdefghijklmnopqrstuvwxyz/ABCDEFGHIJKLMNOPQRSTUVWXYZ(+)'))) {
|
||||||
return false;
|
// Try url_decoding
|
||||||
|
$id = urldecode($id);
|
||||||
|
if (!empty(trim($id, '0123456789abcdefghijklmnopqrstuvwxyz/ABCDEFGHIJKLMNOPQRSTUVWXYZ(+)'))) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return $id;
|
return $id;
|
||||||
@@ -632,6 +643,29 @@ enum MDNodaRepository implements MDValueEnumInterface, JsonSerializable {
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Validates an nomisma ID, returning a string or false.
|
||||||
|
*
|
||||||
|
* @param string $id ID to validate.
|
||||||
|
*
|
||||||
|
* @return string|false
|
||||||
|
*/
|
||||||
|
private static function validateNomismaId(string $id):string|false {
|
||||||
|
|
||||||
|
$id = strtr($id, [
|
||||||
|
"http://nomisma.org/id/" => '',
|
||||||
|
"https://nomisma.org/id/" => '',
|
||||||
|
]);
|
||||||
|
|
||||||
|
// Ensure the remaining string does not contain spaces or slashes
|
||||||
|
foreach (['/', ' '] as $disallowedChar) {
|
||||||
|
if (str_contains($id, $disallowedChar)) return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
return $id;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Validates an NPG ID, returning a string or false.
|
* Validates an NPG ID, returning a string or false.
|
||||||
*
|
*
|
||||||
@@ -761,7 +795,7 @@ enum MDNodaRepository implements MDValueEnumInterface, JsonSerializable {
|
|||||||
]),
|
]),
|
||||||
self::ndp_ikmk => self::validateNdpIkmkForPlaces($id),
|
self::ndp_ikmk => self::validateNdpIkmkForPlaces($id),
|
||||||
self::ndp_ikmk_persons => self::validateNumericId($id, ['https://ikmk.smb.museum/ndp/person/']),
|
self::ndp_ikmk_persons => self::validateNumericId($id, ['https://ikmk.smb.museum/ndp/person/']),
|
||||||
self::nomisma => self::validateNumericId($id, ['http://nomisma.org/id/']),
|
self::nomisma => self::validateNomismaId($id),
|
||||||
self::npg => self::validateNpgId($id),
|
self::npg => self::validateNpgId($id),
|
||||||
self::oberbegriffsdatei => self::validateNumericId($id, ['https://term.museum-digital.de/oberbegriffsdatei/tag/']),
|
self::oberbegriffsdatei => self::validateNumericId($id, ['https://term.museum-digital.de/oberbegriffsdatei/tag/']),
|
||||||
self::orcid => self::validateOrcidId($id),
|
self::orcid => self::validateOrcidId($id),
|
||||||
|
|||||||
@@ -408,8 +408,13 @@ final class MDNodaRepositoryTest extends TestCase {
|
|||||||
public static function iconclassIdForValidationProvider():Generator {
|
public static function iconclassIdForValidationProvider():Generator {
|
||||||
|
|
||||||
yield "45C221 ; url, http" => ["45C221", "http://iconclass.org/rkd/45C221"];
|
yield "45C221 ; url, http" => ["45C221", "http://iconclass.org/rkd/45C221"];
|
||||||
|
yield "45C221 ; url, http, www." => ["45C221", "http://www.iconclass.org/rkd/45C221"];
|
||||||
|
yield "45C221 ; url, http, www., trailing slash" => ["45C221", "http://www.iconclass.org/rkd/45C221/"];
|
||||||
yield "45C221 ; url, https" => ["45C221", "http://iconclass.org/rkd//45C221"];
|
yield "45C221 ; url, https" => ["45C221", "http://iconclass.org/rkd//45C221"];
|
||||||
|
yield "45C221(+321) ; url, https" => ["45C221(+321)", "http://iconclass.org/rkd//45C221(+321)"];
|
||||||
yield "45C221 ; ID" => ["45C221", "45C221"];
|
yield "45C221 ; ID" => ["45C221", "45C221"];
|
||||||
|
yield "45C221(+321) ; ID" => ["45C221(+321)", "45C221(+321)"];
|
||||||
|
yield "45C221(%2B321) > 45C221(+321) ; ID" => ["45C221(+321)", "45C221(%2B321)"];
|
||||||
yield "Broken input / adfdasjfklasäj%l" => [false, "adfdasjfklasäj%l"];
|
yield "Broken input / adfdasjfklasäj%l" => [false, "adfdasjfklasäj%l"];
|
||||||
|
|
||||||
}
|
}
|
||||||
@@ -429,6 +434,36 @@ final class MDNodaRepositoryTest extends TestCase {
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Data provider for validating nomisma entries.
|
||||||
|
*
|
||||||
|
* @return Generator<string, array{0: string|false, 1: string}>
|
||||||
|
*/
|
||||||
|
public static function nomismaIdForValidationProvider():Generator {
|
||||||
|
|
||||||
|
yield "1234 (url, https)" => ["1234", "https://nomisma.org/id/1234"];
|
||||||
|
yield "1234" => ["1234", "https://nomisma.org/id/1234"];
|
||||||
|
yield "glass (url, https)" => ["glass", "https://nomisma.org/id/glass"];
|
||||||
|
yield "glass" => ["glass", "glass"];
|
||||||
|
yield "Broken input / empty string" => [false, ""];
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Ensure validating nomisma references.
|
||||||
|
*
|
||||||
|
* @param string|false $expected Expected output.
|
||||||
|
* @param string $inputString Input string.
|
||||||
|
*
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
|
#[DataProvider('nomismaIdForValidationProvider')]
|
||||||
|
public function testNomismaIdValidation(string|false $expected, string $inputString):void {
|
||||||
|
|
||||||
|
self::assertEquals($expected, MDNodaRepository::nomisma->validateId($inputString));
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Tests conversion of already validated and set up entries to strings.
|
* Tests conversion of already validated and set up entries to strings.
|
||||||
*
|
*
|
||||||
|
|||||||
Reference in New Issue
Block a user