From ce436c3d0a95fd62abff10742130bf5de1c29cb1 Mon Sep 17 00:00:00 2001 From: naman-bruno Date: Fri, 20 Feb 2026 16:04:17 +0530 Subject: [PATCH] fix: window normlize path comparison (#7240) --- .../bruno-electron/src/app/collection-watcher.js | 12 ++++++------ packages/bruno-electron/src/ipc/collection.js | 6 +++++- packages/bruno-electron/src/utils/filesystem.js | 8 ++++---- 3 files changed, 15 insertions(+), 11 deletions(-) diff --git a/packages/bruno-electron/src/app/collection-watcher.js b/packages/bruno-electron/src/app/collection-watcher.js index 038ba0195..5f4c5fda2 100644 --- a/packages/bruno-electron/src/app/collection-watcher.js +++ b/packages/bruno-electron/src/app/collection-watcher.js @@ -36,14 +36,14 @@ const isBrunoConfigFile = (pathname, collectionPath) => { const dirname = path.dirname(pathname); const basename = path.basename(pathname); - return dirname === collectionPath && basename === 'bruno.json'; + return path.normalize(dirname) === path.normalize(collectionPath) && basename === 'bruno.json'; }; const isEnvironmentsFolder = (pathname, collectionPath) => { const dirname = path.dirname(pathname); const envDirectory = path.join(collectionPath, 'environments'); - return dirname === envDirectory; + return path.normalize(dirname) === path.normalize(envDirectory); }; const isFolderRootFile = (pathname, collectionPath) => { @@ -64,7 +64,7 @@ const isCollectionRootFile = (pathname, collectionPath) => { const basename = path.basename(pathname); // return if we are not at the root of the collection - if (dirname !== collectionPath) { + if (path.normalize(dirname) !== path.normalize(collectionPath)) { return false; } @@ -385,7 +385,7 @@ const add = async (win, pathname, collectionUid, collectionPath, useWorkerThread const addDirectory = async (win, pathname, collectionUid, collectionPath) => { const envDirectory = path.join(collectionPath, 'environments'); - if (pathname === envDirectory) { + if (path.normalize(pathname) === path.normalize(envDirectory)) { return; } @@ -563,7 +563,7 @@ const unlink = (win, pathname, collectionUid, collectionPath) => { const basename = path.basename(pathname); const dirname = path.dirname(pathname); - if (basename === 'opencollection.yml' && dirname === collectionPath) { + if (basename === 'opencollection.yml' && path.normalize(dirname) === path.normalize(collectionPath)) { return; } @@ -581,7 +581,7 @@ const unlink = (win, pathname, collectionUid, collectionPath) => { const unlinkDir = async (win, pathname, collectionUid, collectionPath) => { const envDirectory = path.join(collectionPath, 'environments'); - if (pathname === envDirectory) { + if (path.normalize(pathname) === path.normalize(envDirectory)) { return; } diff --git a/packages/bruno-electron/src/ipc/collection.js b/packages/bruno-electron/src/ipc/collection.js index d5d877fde..bea5778f6 100644 --- a/packages/bruno-electron/src/ipc/collection.js +++ b/packages/bruno-electron/src/ipc/collection.js @@ -114,8 +114,12 @@ const findCollectionPathByItemPath = (filePath) => { // Sort by length descending to find the most specific (deepest) match first const sortedPaths = allCollectionPaths.sort((a, b) => b.length - a.length); + // Normalize the file path for comparison + const normalizedFilePath = path.normalize(filePath); + for (const collectionPath of sortedPaths) { - if (filePath.startsWith(collectionPath + path.sep) || filePath === collectionPath) { + const normalizedCollectionPath = path.normalize(collectionPath); + if (normalizedFilePath.startsWith(normalizedCollectionPath + path.sep) || normalizedFilePath === normalizedCollectionPath) { return collectionPath; } } diff --git a/packages/bruno-electron/src/utils/filesystem.js b/packages/bruno-electron/src/utils/filesystem.js index 7e88f0c95..36a8f9b33 100644 --- a/packages/bruno-electron/src/utils/filesystem.js +++ b/packages/bruno-electron/src/utils/filesystem.js @@ -442,7 +442,7 @@ const isDotEnvFile = (pathname, collectionPath) => { const dirname = path.dirname(pathname); const basename = path.basename(pathname); - return dirname === collectionPath && basename === '.env'; + return path.normalize(dirname) === path.normalize(collectionPath) && basename === '.env'; }; const isValidDotEnvFilename = (filename) => { @@ -456,7 +456,7 @@ const isBrunoConfigFile = (pathname, collectionPath) => { const dirname = path.dirname(pathname); const basename = path.basename(pathname); - return dirname === collectionPath && basename === 'bruno.json'; + return path.normalize(dirname) === path.normalize(collectionPath) && basename === 'bruno.json'; }; const isBruEnvironmentConfig = (pathname, collectionPath) => { @@ -464,14 +464,14 @@ const isBruEnvironmentConfig = (pathname, collectionPath) => { const envDirectory = path.join(collectionPath, 'environments'); const basename = path.basename(pathname); - return dirname === envDirectory && hasBruExtension(basename); + return path.normalize(dirname) === path.normalize(envDirectory) && hasBruExtension(basename); }; const isCollectionRootBruFile = (pathname, collectionPath) => { const dirname = path.dirname(pathname); const basename = path.basename(pathname); - return dirname === collectionPath && basename === 'collection.bru'; + return path.normalize(dirname) === path.normalize(collectionPath) && basename === 'collection.bru'; }; module.exports = {