Skip to content

Commit

Permalink
Fix: Import failing for collections with special characters in Windows (
Browse files Browse the repository at this point in the history
#3969)

* fix: correct variable used in collection name update
* fix: sanitize collection names by removing invalid filesystem characters
* refactor: refactor collection name sanitization to use `sanitizeDirectoryName`
  • Loading branch information
Pragadesh-45 authored Feb 10, 2025
1 parent 667b153 commit 5291bba
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 10 deletions.
7 changes: 2 additions & 5 deletions packages/bruno-electron/src/ipc/collection.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ const {
normalizeWslPath,
normalizeAndResolvePath,
safeToRename,
sanitizeCollectionName,
isWindowsOS,
isValidFilename,
hasSubDirectories,
Expand Down Expand Up @@ -76,7 +75,6 @@ const registerRendererEventHandlers = (mainWindow, watcher, lastOpenedCollection
async (event, collectionName, collectionFolderName, collectionLocation) => {
try {
collectionFolderName = sanitizeDirectoryName(collectionFolderName);
collectionName = sanitizeCollectionName(collectionName);
const dirPath = path.join(collectionLocation, collectionFolderName);
if (fs.existsSync(dirPath)) {
const files = fs.readdirSync(dirPath);
Expand Down Expand Up @@ -118,7 +116,7 @@ const registerRendererEventHandlers = (mainWindow, watcher, lastOpenedCollection
ipcMain.handle(
'renderer:clone-collection',
async (event, collectionName, collectionFolderName, collectionLocation, previousPath) => {
collectionFolderName = sanitizeCollectionName(collectionFolderName);
collectionFolderName = sanitizeDirectoryName(collectionFolderName);
const dirPath = path.join(collectionLocation, collectionFolderName);
if (fs.existsSync(dirPath)) {
throw new Error(`collection: ${dirPath} already exists`);
Expand Down Expand Up @@ -168,7 +166,6 @@ const registerRendererEventHandlers = (mainWindow, watcher, lastOpenedCollection
// rename collection
ipcMain.handle('renderer:rename-collection', async (event, newName, collectionPathname) => {
try {
newName = sanitizeCollectionName(newName);
const brunoJsonFilePath = path.join(collectionPathname, 'bruno.json');
const content = fs.readFileSync(brunoJsonFilePath, 'utf8');
const json = JSON.parse(content);
Expand Down Expand Up @@ -521,7 +518,7 @@ const registerRendererEventHandlers = (mainWindow, watcher, lastOpenedCollection

ipcMain.handle('renderer:import-collection', async (event, collection, collectionLocation) => {
try {
let collectionName = sanitizeCollectionName(collection.name);
let collectionName = sanitizeDirectoryName(collection.name);
let collectionPath = path.join(collectionLocation, collectionName);

if (fs.existsSync(collectionPath)) {
Expand Down
5 changes: 0 additions & 5 deletions packages/bruno-electron/src/utils/filesystem.js
Original file line number Diff line number Diff line change
Expand Up @@ -154,10 +154,6 @@ const searchForBruFiles = (dir) => {
return searchForFiles(dir, '.bru');
};

const sanitizeCollectionName = (name) => {
return name.trim();
}

const sanitizeDirectoryName = (name) => {
return name.replace(/[<>:"/\\|?*\x00-\x1F]+/g, '-').trim();
};
Expand Down Expand Up @@ -267,7 +263,6 @@ module.exports = {
searchForFiles,
searchForBruFiles,
sanitizeDirectoryName,
sanitizeCollectionName,
isWindowsOS,
safeToRename,
isValidFilename,
Expand Down

0 comments on commit 5291bba

Please sign in to comment.