fix: update pathname validation to use basename for directory checks #2193 (#3550)

* fix: implement custom pathname validation #2193

* fix: update pathname validation to use basename for directory checks

* fix: improve error message for invalid pathname in collection.js
This commit is contained in:
Pragadesh-45 2024-12-15 15:08:36 +05:30 committed by GitHub
parent a6ac98b709
commit 086c4c063e
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -76,9 +76,8 @@ const registerRendererEventHandlers = (mainWindow, watcher, lastOpenedCollection
throw new Error(`collection: ${dirPath} already exists and is not empty`);
}
}
if (!isValidPathname(dirPath)) {
throw new Error(`collection: invalid pathname - ${dir}`);
if (!isValidPathname(path.basename(dirPath))) {
throw new Error(`collection: invalid pathname - ${dirPath}`);
}
if (!fs.existsSync(dirPath)) {
@ -111,8 +110,8 @@ const registerRendererEventHandlers = (mainWindow, watcher, lastOpenedCollection
throw new Error(`collection: ${dirPath} already exists`);
}
if (!isValidPathname(dirPath)) {
throw new Error(`collection: invalid pathname - ${dir}`);
if (!isValidPathname(path.basename(dirPath))) {
throw new Error(`collection: invalid pathname - ${dirPath}`);
}
// create dir