Merge pull request #5123 from Pragadesh-45/fix/collection-path-validator

This commit is contained in:
Pragadesh-45
2025-07-16 21:36:46 +05:30
committed by GitHub
parent ba5eb53548
commit 645b7e721a
2 changed files with 13 additions and 5 deletions

View File

@@ -59,13 +59,21 @@ const envHasSecrets = (environment = {}) => {
return secrets && secrets.length > 0;
};
const validatePathIsInsideCollection = (path) => {
const validatePathIsInsideCollection = (filePath, lastOpenedCollections) => {
const openCollectionPaths = collectionWatcher.getAllWatcherPaths();
const isValid = openCollectionPaths.some((collectionPath) => {
return path.startsWith(collectionPath);
const lastOpenedPaths = lastOpenedCollections ? lastOpenedCollections.getAll() : [];
// Combine both currently watched collections and last opened collections
// todo: remove the lastOpenedPaths from the list
// todo: have a proper way to validate the path without the active watcher logic
const allCollectionPaths = [...new Set([...openCollectionPaths, ...lastOpenedPaths])];
const isValid = allCollectionPaths.some((collectionPath) => {
return filePath.startsWith(collectionPath + path.sep) || filePath === collectionPath;
});
if (!isValid) {
throw new Error(`Path: ${path} should be inside a collection`);
throw new Error(`Path: ${filePath} should be inside a collection`);
}
}
@@ -247,7 +255,7 @@ const registerRendererEventHandlers = (mainWindow, watcher, lastOpenedCollection
if (!validateName(request?.filename)) {
throw new Error(`${request.filename}.bru is not a valid filename`);
}
validatePathIsInsideCollection(pathname);
validatePathIsInsideCollection(pathname, lastOpenedCollections);
const content = await jsonToBruViaWorker(request);
await writeFile(pathname, content);
} catch (error) {