Skip to content

Commit

Permalink
wip: Prevent users from creating guided mode datasets with forbidden …
Browse files Browse the repository at this point in the history
…characters
  • Loading branch information
JacobiClark committed Nov 13, 2024
1 parent e25600b commit 87b00c1
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 3 deletions.
10 changes: 7 additions & 3 deletions src/renderer/src/scripts/guided-mode/guided-curate-dataset.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
2 changes: 2 additions & 0 deletions src/renderer/src/scripts/others/renderer.js
Original file line number Diff line number Diff line change
Expand Up @@ -4359,13 +4359,15 @@ const namesOfForbiddenFiles = {

const sparcFolderAndFileRegex = /[\+&\%#]/;
const identifierConventionsRegex = /^[a-zA-Z0-9-_]+$/;
const forbiddenCharacters = /[@#$%^&*()+=\/\\|"'~;:<>{}\[\]?]/;

window.evaluateStringAgainstSdsRequirements = (stringToTest, stringCase) => {
const testCases = {
"folder-and-file-name-is-valid": !sparcFolderAndFileRegex.test(stringToTest), // returns true if the string is valid
"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];
};
Expand Down

0 comments on commit 87b00c1

Please sign in to comment.