From 87b00c109092aab2e42e66ac3ea98a8218b1b96a Mon Sep 17 00:00:00 2001 From: jacobiclark Date: Wed, 13 Nov 2024 12:58:42 -0800 Subject: [PATCH] wip: Prevent users from creating guided mode datasets with forbidden characters --- .../src/scripts/guided-mode/guided-curate-dataset.js | 10 +++++++--- src/renderer/src/scripts/others/renderer.js | 2 ++ 2 files changed, 9 insertions(+), 3 deletions(-) diff --git a/src/renderer/src/scripts/guided-mode/guided-curate-dataset.js b/src/renderer/src/scripts/guided-mode/guided-curate-dataset.js index c6aeb7e6f..16659d5ef 100644 --- a/src/renderer/src/scripts/guided-mode/guided-curate-dataset.js +++ b/src/renderer/src/scripts/guided-mode/guided-curate-dataset.js @@ -1095,11 +1095,15 @@ const savePageChanges = async (pageBeingLeftID) => { message: "Please enter a dataset name.", }); } - if (check_forbidden_characters_ps(datasetNameInput)) { + + const datasetNameContainsForbiddenCharacters = window.evaluateStringAgainstSdsRequirements( + datasetNameInput, + "string-contains-forbidden-characters" + ); + if (datasetNameContainsForbiddenCharacters) { errorArray.push({ type: "notyf", - message: - "A Pennsieve dataset name cannot contain any of the following characters: /:*?'<>.", + message: `A Pennsieve dataset name cannot contain any of the following characters: @#$%^&*()+=/\|"'~;:<>{}[]?`, }); } if (!datasetSubtitleInput) { diff --git a/src/renderer/src/scripts/others/renderer.js b/src/renderer/src/scripts/others/renderer.js index 6b4992f25..8a5e1bf8c 100644 --- a/src/renderer/src/scripts/others/renderer.js +++ b/src/renderer/src/scripts/others/renderer.js @@ -4359,6 +4359,7 @@ const namesOfForbiddenFiles = { const sparcFolderAndFileRegex = /[\+&\%#]/; const identifierConventionsRegex = /^[a-zA-Z0-9-_]+$/; +const forbiddenCharacters = /[@#$%^&*()+=\/\\|"'~;:<>{}\[\]?]/; window.evaluateStringAgainstSdsRequirements = (stringToTest, stringCase) => { const testCases = { @@ -4366,6 +4367,7 @@ window.evaluateStringAgainstSdsRequirements = (stringToTest, stringCase) => { "file-is-hidden": stringToTest.startsWith("."), // returns true if the string is hidden "file-is-in-forbidden-files-list": namesOfForbiddenFiles?.[stringToTest], // returns true if the string is in the forbidden files list "string-adheres-to-identifier-conventions": identifierConventionsRegex.test(stringToTest), // returns true if the string adheres to the identifier conventions + "string-contains-forbidden-characters": forbiddenCharacters.test(stringToTest), // returns true if the string contains forbidden characters }; return testCases[stringCase]; };