Improve validation of ORCID IDs

This commit is contained in:
Joshua Ramon Enslin 2024-10-03 16:36:01 +02:00
parent d22db5bd95
commit 333340da3e
Signed by: jrenslin
GPG Key ID: 46016F84501B70AE

View File

@ -531,6 +531,24 @@ enum MDNodaRepository implements MDValueEnumInterface, JsonSerializable {
}
/**
* Validates OrCID IDs.
*
* @param string $id ID to validate.
*
* @return string|false
*/
private static function validateOrcidId(string $id):string|false {
$id = strtr(trim($id, '/'), [
"http://orcid.org/" => "",
"https://orcid.org/" => "",
]);
return preg_match('/^[0-9]{4}-[0-9]{4}-[0-9]{4}-[0-9]{4}$/', $id) ? $id : false;
}
/**
* Validates a PIM ID, returning a string or false.
*
@ -679,7 +697,7 @@ enum MDNodaRepository implements MDValueEnumInterface, JsonSerializable {
self::nomisma => str_replace('http://nomisma.org/id/', '', $id),
self::npg => self::validateNpgId($id),
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::orcid => self::validateOrcidId($id),
self::osm => self::validateNumericId($id, ['https://www.openstreetmap.org/relation/']),
self::pim => self::validatePimId($id),
self::pleiades => self::validateNumericId($id, ['https://pleiades.stoa.org/places/']),