From 262507699eb2ce25891633cd52c715c28aa3c81d Mon Sep 17 00:00:00 2001 From: Jacob Clark Date: Fri, 4 Oct 2024 10:42:02 -0700 Subject: [PATCH] wip: Update folder/file Regex check --- src/renderer/src/scripts/others/renderer.js | 19 ++++++++++--------- 1 file changed, 10 insertions(+), 9 deletions(-) diff --git a/src/renderer/src/scripts/others/renderer.js b/src/renderer/src/scripts/others/renderer.js index eb4784757..3c7f3043f 100644 --- a/src/renderer/src/scripts/others/renderer.js +++ b/src/renderer/src/scripts/others/renderer.js @@ -4350,23 +4350,24 @@ window.replaceProblematicFilesWithSDSCompliantNames = (datasetStructure) => { // } // }; -const namesOfForbiddenFiles = { +const forbiddenFiles = { ".DS_Store": true, "Thumbs.db": true, }; -const sparcFolderAndFileRegex = /[\+&\%#]/; +const validSparcFolderAndFileNameRegex = /^[0-9A-Za-z,.-_ ]+$/; const identifierConventionsRegex = /^[a-zA-Z0-9-_]+$/; -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 +window.evaluateStringAgainstSdsRequirements = (stringToTest, testType) => { + const tests = { + "is-valid-folder-or-file-name": validSparcFolderAndFileNameRegex.test(stringToTest), + "is-hidden-file": stringToTest.startsWith("."), + "is-forbidden-file": forbiddenFiles[stringToTest] === true, + "adheres-to-identifier-conventions": identifierConventionsRegex.test(stringToTest), }; - return testCases[stringCase]; + return tests[testType]; }; + let loadingSweetAlert; let loadingSweetAlertTimer;