Remove whitespaces from vocabulary links, add dedicated exception for

lcsh links that are actually loc links
This commit is contained in:
2023-10-16 16:44:33 +02:00
parent da6e40282d
commit 1d1a690e0f
4 changed files with 31 additions and 2 deletions

View File

@ -351,6 +351,7 @@ enum MDNodaRepository implements MDValueEnumInterface, JsonSerializable {
return false;
}
if (is_numeric(strtr($id, ['-' => '', 'X' => ''])) === false) {
throw new Exception($id);
return false;
}
@ -409,7 +410,10 @@ enum MDNodaRepository implements MDValueEnumInterface, JsonSerializable {
}
if (substr($id, 0, 2) !== 'sh') {
throw new MDInvalidNodaLinkException("LCSH IDs must start with sh");
if (str_starts_with(substr($id, 0, 1), 'n')) {
throw new MDInvalidNodaLinkLcshIdIsGeneralLoc("LCSH IDs must start with sh. ID started with n. Use general LOC link instead.");
}
throw new MDInvalidNodaLinkException("LCSH IDs must start with sh. ID provided is: " . $id);
}
if (filter_var(ltrim(substr($id, 2), "0"), FILTER_VALIDATE_INT) === false) {
@ -538,6 +542,10 @@ enum MDNodaRepository implements MDValueEnumInterface, JsonSerializable {
'https://en.wikipedia.org/wiki/' => '',
'http://fr.wikipedia.org/wiki/' => '',
'https://fr.wikipedia.org/wiki/' => '',
'http://id.wikipedia.org/wiki/' => '',
'https://id.wikipedia.org/wiki/' => '',
'http://it.wikipedia.org/wiki/' => '',
'https://it.wikipedia.org/wiki/' => '',
'http://nl.wikipedia.org/wiki/' => '',
'https://nl.wikipedia.org/wiki/' => '',
'http://sv.wikipedia.org/wiki/' => '',