Skip to content

Commit

Permalink
Merge pull request #475 from datacite/fix_purl_validator
Browse files Browse the repository at this point in the history
fix: use url validator rather than regexp
  • Loading branch information
kjgarza authored Oct 26, 2020
2 parents 193aa07 + a739eb1 commit cbfd605
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 4 deletions.
4 changes: 2 additions & 2 deletions app/components/doi-related-identifier.js
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ export default Component.extend({
updateRelatedIdentifier(value) {
const ark = /^ark:\/[0-9]{5}\/\S+$/;
const lsid = /^[uU][rR][nN]:[lL][sS][iI][dD]:(A-Za-z0-9][A-Za-z0-9()+,-.=@;$_!*'"%]):(A-Za-z0-9][A-Za-z0-9()+,-.=@;$_!*'"%]):(A-Za-z0-9][A-Za-z0-9()+,-.=@;$_!*'"%])[:]?(A-Za-z0-9][A-Za-z0-9()+,-.=@;$_!*'"%])?$/;
const purl = /^http?:\/\/(purl\.oclc\.org\/)/;
const purl = {require_host: true, host_whitelist: [ 'purl.org', 'oclc.org' ]};
const arxiv = /^(arXiv:)(\d{4}.\d{4,5}|[a-z\-]+(\.[A-Z]{2})?\/\d{7})(v\d+)?/;
const doi = /^(10\.\d{4,5}\/.+)/;
const bibcode = /\d{4}[A-Za-z\.\&]{5}[\w\.]{4}[ELPQ-Z\.][\d\.]{4}[A-Z]/;
Expand Down Expand Up @@ -151,7 +151,7 @@ export default Component.extend({
this.fragment.set('relatedIdentifierType', 'LSID');
this.set('controlledIdentifierType', true);
break;
case purl.test(value):
case isURL(value, purl):
this.fragment.set('relatedIdentifier', value);
this.fragment.set('relatedIdentifierType', 'PURL');
this.set('controlledIdentifierType', true);
Expand Down
4 changes: 2 additions & 2 deletions app/validators/identifier-format.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ const IdentifierFormat = BaseValidator.extend({
validate(value, options, model) {
const ark = /^ark:\/[0-9]{5}\/\S+$/;
const lsid = /^[uU][rR][nN]:[lL][sS][iI][dD]:(A-Za-z0-9][A-Za-z0-9()+,-.=@;$_!*'"%]):(A-Za-z0-9][A-Za-z0-9()+,-.=@;$_!*'"%]):(A-Za-z0-9][A-Za-z0-9()+,-.=@;$_!*'"%])[:]?(A-Za-z0-9][A-Za-z0-9()+,-.=@;$_!*'"%])?$/;
const purl = /^http?:\/\/(purl\.oclc\.org\/)/;
const purl = {require_host: true, host_whitelist: [ 'purl.org', 'oclc.org' ]};
const arxiv = /^(arXiv:)(\d{4}.\d{4,5}|[a-z\-]+(\.[A-Z]{2})?\/\d{7})(v\d+)?/;
const doi = /^(10\.\d{4,5}\/.+)/;
const bibcode = /\d{4}[A-Za-z\.\&]{5}[\w\.]{4}[ELPQ-Z\.][\d\.]{4}[A-Z]/;
Expand All @@ -26,7 +26,7 @@ const IdentifierFormat = BaseValidator.extend({
case model.relatedIdentifierType == 'LSID':
return lsid.test(value) ? true : 'Please enter a valid LSID.';
case model.relatedIdentifierType == 'PURL':
return purl.test(value) ? true : 'Please enter a valid PURL.';
return isURL(value, purl) ? true : 'Please enter a valid PURL.';
case model.relatedIdentifierType == 'URN':
return urn.test(value) ? true : 'Please enter a valid URN.';
case model.relatedIdentifierType == 'ISBN':
Expand Down

0 comments on commit cbfd605

Please sign in to comment.