From b0e9c6d80dea1c07e29cf79014acbab0f0ec693e Mon Sep 17 00:00:00 2001 From: JacobiClark Date: Thu, 19 Dec 2024 14:46:41 -0800 Subject: [PATCH] fix: Change regex to replace all invalid characters in fol/file names --- src/renderer/src/scripts/others/renderer.js | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/src/renderer/src/scripts/others/renderer.js b/src/renderer/src/scripts/others/renderer.js index d8c5354c6..c3d01025a 100644 --- a/src/renderer/src/scripts/others/renderer.js +++ b/src/renderer/src/scripts/others/renderer.js @@ -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"); @@ -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"); @@ -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