Skip to content

Commit

Permalink
Added check for valid HTTP url
Browse files Browse the repository at this point in the history
  • Loading branch information
BryceMarshall committed Nov 3, 2023
1 parent 019d692 commit 8bc1a56
Showing 1 changed file with 12 additions and 1 deletion.
13 changes: 12 additions & 1 deletion src/utils/validate.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,17 @@ export const validateURL = (url) => !url || validator.isURL(url);

// See https://stackoverflow.com/a/48524047/7416701
export const doiRegexp = /^(https:\/\/doi.org\/)?10\.\d{4,9}\/[-._;()/:A-Z0-9]+$/i;
function isValidHttpUrl(string) {
let url;

try {
url = new URL(string);
} catch (_) {
return false;
}

return url.protocol === "http:" || url.protocol === "https:";
}

const validateLatitude = (num) => num >= -90 && num <= 90;

Expand Down Expand Up @@ -70,7 +81,7 @@ const validators = {
},
},
datasetIdentifier: {
validation: (val) => !val || doiRegexp.test(val),
validation: (val) => !val || (doiRegexp.test(val) && isValidHttpUrl(val)),
optional: true,
tab: "dataID",
error: {
Expand Down

0 comments on commit 8bc1a56

Please sign in to comment.