From 086c4c063e43c594ef0b0822cace611027dc31ab Mon Sep 17 00:00:00 2001 From: Pragadesh-45 <54320162+Pragadesh-45@users.noreply.github.com> Date: Sun, 15 Dec 2024 15:08:36 +0530 Subject: [PATCH] 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 --- packages/bruno-electron/src/ipc/collection.js | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/packages/bruno-electron/src/ipc/collection.js b/packages/bruno-electron/src/ipc/collection.js index 8ca24ebcb..ef6f98218 100644 --- a/packages/bruno-electron/src/ipc/collection.js +++ b/packages/bruno-electron/src/ipc/collection.js @@ -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