Skip to content

Commit

Permalink
bugfix: handling invalid import environment names (usebruno#2197)
Browse files Browse the repository at this point in the history
  • Loading branch information
busy-panda committed May 1, 2024
1 parent 392cc80 commit bbb03d0
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 4 deletions.
7 changes: 4 additions & 3 deletions packages/bruno-electron/src/ipc/collection.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,8 @@ const {
browseFiles,
createDirectory,
searchForBruFiles,
sanitizeDirectoryName
sanitizeDirectoryName,
sanitizeFileName
} = require('../utils/filesystem');
const { openCollectionDialog } = require('../app/collections');
const { generateUidBasedOnHash, stringifyJson, safeParseJSON, safeStringifyJSON } = require('../utils/common');
Expand Down Expand Up @@ -218,13 +219,13 @@ const registerRendererEventHandlers = (mainWindow, watcher, lastOpenedCollection
await createDirectory(envDirPath);
}

const envFilePath = path.join(envDirPath, `${name}.bru`);
const envFilePath = path.join(envDirPath, `${sanitizeFileName(name)}.bru`);
if (fs.existsSync(envFilePath)) {
throw new Error(`environment: ${envFilePath} already exists`);
}

const environment = {
name: name,
name: sanitizeFileName(name),
variables: variables || []
};

Expand Down
6 changes: 5 additions & 1 deletion packages/bruno-electron/src/utils/filesystem.js
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,9 @@ const searchForBruFiles = (dir) => {
const sanitizeDirectoryName = (name) => {
return name.replace(/[<>:"/\\|?*\x00-\x1F]+/g, '-');
};
const sanitizeFileName = (name) => {
return sanitizeDirectoryName(name);
};

module.exports = {
isValidPathname,
Expand All @@ -164,5 +167,6 @@ module.exports = {
chooseFileToSave,
searchForFiles,
searchForBruFiles,
sanitizeDirectoryName
sanitizeDirectoryName,
sanitizeFileName
};

0 comments on commit bbb03d0

Please sign in to comment.