Skip to content

Commit

Permalink
fix: Change regex to replace all invalid characters in fol/file names
Browse files Browse the repository at this point in the history
  • Loading branch information
JacobiClark committed Dec 19, 2024
1 parent 3f4af43 commit b0e9c6d
Showing 1 changed file with 5 additions and 4 deletions.
9 changes: 5 additions & 4 deletions src/renderer/src/scripts/others/renderer.js
Original file line number Diff line number Diff line change
Expand Up @@ -4323,7 +4323,7 @@ const replaceProblematicFoldersWithSDSCompliantNames = (datasetStructure) => {
// If the folder name is not valid, replace it with a valid name and then recurse through the
// renamed folder to check for any other problematic folders
if (!folderNameIsValid) {
const newFolderName = folderKey.replace(sparcFolderAndFileRegex, "-");
const newFolderName = folderKey.replace(invalidSparcFolderAndFileNameRegexReplacer, "-");
const newFolderObj = { ...datasetStructure["folders"][folderKey] };
if (!newFolderObj["action"].includes("renamed")) {
newFolderObj["action"].push("renamed");
Expand All @@ -4347,7 +4347,7 @@ window.replaceProblematicFilesWithSDSCompliantNames = (datasetStructure) => {
"folder-and-file-name-is-valid"
);
if (!fileNameIsValid) {
const newFileName = fileKey.replace(sparcFolderAndFileRegex, "-");
const newFileName = fileKey.replace(invalidSparcFolderAndFileNameRegexReplacer, "-");
const newFileObj = { ...datasetStructure["files"][fileKey] };
if (!newFileObj["action"].includes("renamed")) {
newFileObj["action"].push("renamed");
Expand Down Expand Up @@ -4389,13 +4389,14 @@ const namesOfForbiddenFiles = {
"Thumbs.db": true,
};

const sparcFolderAndFileRegex = /[\+&\%#]/;
const invalidSparcFolderAndFileNameRegexMatcher = /[\+&\%#]/;
const invalidSparcFolderAndFileNameRegexReplacer = /[\+&\%#]/g;
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
"folder-and-file-name-is-valid": !invalidSparcFolderAndFileNameRegexMatcher.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
Expand Down

0 comments on commit b0e9c6d

Please sign in to comment.