Properly validate PIM IDs

Close #20
This commit is contained in:
jrenslin committed 2023-09-01 12:30:47 +02:00
1 parent f79afa4ed7
commit 0f64939def
2 files changed
+39 -3

No files matched your search

+33 -1
View File
@@ -399,6 +399,38 @@ private static function validateLcshId(string $id):string|false {
}
/**
* Validates a PIM ID, returning a string or false.
*
* @param string $id ID to validate.
*
* @return string|false
*/
private static function validatePimId(string $id):string|false {
if (filter_var($id, FILTER_VALIDATE_URL) !== false) {
$toRemove = [];
foreach ([
'https://opac-nevter.pim.hu/en/record/-/record/',
'https://resolver.pim.hu/auth/',
] as $prefix) {
$toRemove[$prefix] = "";
}
$id = strtr($id, $toRemove);
}
// There is an issue with this regex
if (preg_match("/^[0-9-PIM]*$/", $id) === false) {
return false;
}
if (is_numeric(substr($id, 3)) === false) {
return false;
}
return $id;
}
/**
* Validates a wikidata ID, returning a string or false.
*
@@ -484,7 +516,7 @@ public function validateId(string $id):string|false {
self::oberbegriffsdatei => self::validateNumericId($id, ['https://term.museum-digital.de/oberbegriffsdatei/tag/']),
self::orcid => preg_match('/^[0-9]{4}-[0-9]{4}-[0-9]{4}-[0-9]{4}$/', $id) ? $id : false,
self::osm => self::validateNumericId($id, ['https://www.openstreetmap.org/relation/']),
self::pim => self::validateNumericId($id, ['https://opac-nevter.pim.hu/en/record/-/record/']),
self::pim => self::validatePimId($id),
self::pleiades => self::validateNumericId($id, ['https://pleiades.stoa.org/places/']),
self::rkd => self::validateNumericId($id, ['http://rkd.nl/explore/artists/', 'https://rkd.nl/explore/artists/']),
self::ulan => self::validateNumericId($id, ['http://vocab.getty.edu/ulan/', 'http://vocab.getty.edu/page/ulan/', 'https://vocab.getty.edu/page/ulan/']),