fix: window normlize path comparison (#7240)

This commit is contained in:
naman-bruno
2026-02-20 16:04:17 +05:30
committed by Bijin A B
parent 0923cc188d
commit ce436c3d0a
3 changed files with 15 additions and 11 deletions

View File

@@ -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;
}

View File

@@ -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;
}
}

View File

@@ -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 = {