Skip to content

Commit

Permalink
MBS-12665: Somewhat widen DNB regex
Browse files Browse the repository at this point in the history
We took this from Wikidata, but given the valid example added
as a test here, it was too strict. Widening it to allow any number,
not just 3, as the first digit in the last case.
  • Loading branch information
reosarevok committed Oct 13, 2022
1 parent 47b118a commit 9fdcf8e
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 5 deletions.
10 changes: 5 additions & 5 deletions root/static/scripts/edit/URLCleanup.js
Original file line number Diff line number Diff line change
Expand Up @@ -1801,8 +1801,8 @@ const CLEANUPS: CleanupEntries = {
restrict: [LINK_TYPES.otherdatabases],
clean: function (url) {
url = url.replace(/^(?:https?:\/\/)?(?:[^\/]+\.)?d-nb\.info\//, 'http://d-nb.info/');
url = url.replace(/^(?:https?:\/\/)?(?:[^\/]+\.)?dnb\.de\/opac(?:\.htm\?)?.*\bquery=nid%3D(1[012]?\d{7}[0-9X]|[47]\d{6}-\d|[1-9]\d{0,7}-[0-9X]|3\d{7}[0-9X]).*$/, 'http://d-nb.info/gnd/$1');
url = url.replace(/^(?:https?:\/\/)?(?:[^\/]+\.)?dnb\.de\/opac(?:\.htm\?)?.*\bquery=idn%3D(1[012]?\d{7}[0-9X]|[47]\d{6}-\d|[1-9]\d{0,7}-[0-9X]|3\d{7}[0-9X]).*$/, 'http://d-nb.info/$1');
url = url.replace(/^(?:https?:\/\/)?(?:[^\/]+\.)?dnb\.de\/opac(?:\.htm\?)?.*\bquery=nid%3D(1[012]?\d{7}[0-9X]|[47]\d{6}-\d|[1-9]\d{0,7}-[0-9X]|[1-9]\d{7}[0-9X]).*$/, 'http://d-nb.info/gnd/$1');
url = url.replace(/^(?:https?:\/\/)?(?:[^\/]+\.)?dnb\.de\/opac(?:\.htm\?)?.*\bquery=idn%3D(1[012]?\d{7}[0-9X]|[47]\d{6}-\d|[1-9]\d{0,7}-[0-9X]|[1-9]\d{7}[0-9X]).*$/, 'http://d-nb.info/$1');
return url;
},
validate: function (url, id) {
Expand All @@ -1812,17 +1812,17 @@ const CLEANUPS: CleanupEntries = {
case LINK_TYPES.otherdatabases.series:
case LINK_TYPES.otherdatabases.work:
return {
result: /^http:\/\/d-nb\.info\/(?:gnd\/)?(?:1[012]?\d{7}[0-9X]|[47]\d{6}-\d|[1-9]\d{0,7}-[0-9X]|3\d{7}[0-9X])$/.test(url),
result: /^http:\/\/d-nb\.info\/(?:gnd\/)?(?:1[012]?\d{7}[0-9X]|[47]\d{6}-\d|[1-9]\d{0,7}-[0-9X]|[1-9]\d{7}[0-9X])$/.test(url),
target: ERROR_TARGETS.ENTITY,
};
case LINK_TYPES.otherdatabases.label:
return {
result: /^http:\/\/d-nb\.info\/(?:(?:dnbn|gnd)\/)?(?:1[012]?\d{7}[0-9X]|[47]\d{6}-\d|[1-9]\d{0,7}-[0-9X]|3\d{7}[0-9X])$/.test(url),
result: /^http:\/\/d-nb\.info\/(?:(?:dnbn|gnd)\/)?(?:1[012]?\d{7}[0-9X]|[47]\d{6}-\d|[1-9]\d{0,7}-[0-9X]|[1-9]\d{7}[0-9X])$/.test(url),
target: ERROR_TARGETS.ENTITY,
};
case LINK_TYPES.otherdatabases.release:
return {
result: /^http:\/\/d-nb\.info\/(?:1[012]?\d{7}[0-9X]|[47]\d{6}-\d|[1-9]\d{0,7}-[0-9X]|3\d{7}[0-9X])$/.test(url),
result: /^http:\/\/d-nb\.info\/(?:1[012]?\d{7}[0-9X]|[47]\d{6}-\d|[1-9]\d{0,7}-[0-9X]|[1-9]\d{7}[0-9X])$/.test(url),
target: ERROR_TARGETS.ENTITY,
};
}
Expand Down
7 changes: 7 additions & 0 deletions root/static/scripts/tests/Control/URLCleanup.js
Original file line number Diff line number Diff line change
Expand Up @@ -1728,6 +1728,13 @@ limited_link_type_combinations: [
expected_clean_url: 'http://d-nb.info/1181136512',
only_valid_entity_types: ['artist', 'label', 'place', 'release', 'series', 'work'],
},
{
input_url: 'http://d-nb.info/97248485X',
input_entity_type: 'release',
expected_relationship_type: 'otherdatabases',
expected_clean_url: 'http://d-nb.info/97248485X',
only_valid_entity_types: ['artist', 'label', 'place', 'release', 'series', 'work'],
},
// Dogmazic
{
input_url: 'https://play.dogmazic.net/artists.php?action=show_all_songs&artist=2283',
Expand Down

0 comments on commit 9fdcf8e

Please sign in to comment.