diff --git a/src/components/Tabs/IdentificationTab.jsx b/src/components/Tabs/IdentificationTab.jsx index a9d29820..c2c5fe7f 100644 --- a/src/components/Tabs/IdentificationTab.jsx +++ b/src/components/Tabs/IdentificationTab.jsx @@ -128,7 +128,7 @@ const IdentificationTab = ({ async function handleUpdateDraftDOI() { setLoadingDoiUpdate(true); - + try { const mappedDataCiteObject = recordToDataCite(record, language, region); delete mappedDataCiteObject.data.type; @@ -141,7 +141,7 @@ const IdentificationTab = ({ const response = await updateDraftDoi( dataObject ); const statusCode = response.data.status; - + if (statusCode === 200) { setDoiUpdateFlag(true); } else { @@ -701,7 +701,7 @@ const IdentificationTab = ({ What is the DOI for this dataset? Eg, Quel est le DOI de ce jeu de données ? Par exemple, {" "} - 10.0000/0000 + https://doi.org/10.0000/0000 {showGenerateDoi && ( @@ -738,8 +738,8 @@ const IdentificationTab = ({ )} {showUpdateDoi && ( - @@ -755,8 +755,8 @@ const IdentificationTab = ({ )} {showDeleteDoi && ( - diff --git a/src/utils/validate.js b/src/utils/validate.js index 759a2f32..b5124564 100644 --- a/src/utils/validate.js +++ b/src/utils/validate.js @@ -4,7 +4,18 @@ export const validateEmail = (email) => !email || validator.isEmail(email); export const validateURL = (url) => !url || validator.isURL(url); // See https://stackoverflow.com/a/48524047/7416701 -export const doiRegexp = /^10.\d{4,9}\/[-._;()/:A-Z0-9]+$/i; +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; @@ -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: {