@@ -20,6 +20,7 @@ const {
20
20
normalizeWslPath,
21
21
normalizeAndResolvePath,
22
22
safeToRename,
23
+ sanitizeCollectionName,
23
24
isWindowsOS,
24
25
isValidFilename,
25
26
hasSubDirectories,
@@ -68,6 +69,8 @@ const registerRendererEventHandlers = (mainWindow, watcher, lastOpenedCollection
68
69
'renderer:create-collection' ,
69
70
async ( event , collectionName , collectionFolderName , collectionLocation ) => {
70
71
try {
72
+ collectionFolderName = sanitizeDirectoryName ( collectionFolderName ) ;
73
+ collectionName = sanitizeCollectionName ( collectionName ) ;
71
74
const dirPath = path . join ( collectionLocation , collectionFolderName ) ;
72
75
if ( fs . existsSync ( dirPath ) ) {
73
76
const files = fs . readdirSync ( dirPath ) ;
@@ -105,6 +108,7 @@ const registerRendererEventHandlers = (mainWindow, watcher, lastOpenedCollection
105
108
ipcMain . handle (
106
109
'renderer:clone-collection' ,
107
110
async ( event , collectionName , collectionFolderName , collectionLocation , previousPath ) => {
111
+ collectionFolderName = sanitizeCollectionName ( collectionFolderName ) ;
108
112
const dirPath = path . join ( collectionLocation , collectionFolderName ) ;
109
113
if ( fs . existsSync ( dirPath ) ) {
110
114
throw new Error ( `collection: ${ dirPath } already exists` ) ;
@@ -150,6 +154,7 @@ const registerRendererEventHandlers = (mainWindow, watcher, lastOpenedCollection
150
154
// rename collection
151
155
ipcMain . handle ( 'renderer:rename-collection' , async ( event , newName , collectionPathname ) => {
152
156
try {
157
+ newName = sanitizeCollectionName ( newName ) ;
153
158
const brunoJsonFilePath = path . join ( collectionPathname , 'bruno.json' ) ;
154
159
const content = fs . readFileSync ( brunoJsonFilePath , 'utf8' ) ;
155
160
const json = JSON . parse ( content ) ;
@@ -442,6 +447,8 @@ const registerRendererEventHandlers = (mainWindow, watcher, lastOpenedCollection
442
447
443
448
// new folder
444
449
ipcMain . handle ( 'renderer:new-folder' , async ( event , pathname ) => {
450
+ const resolvedFolderName = sanitizeDirectoryName ( path . basename ( pathname ) ) ;
451
+ pathname = path . join ( path . dirname ( pathname ) , resolvedFolderName ) ;
445
452
try {
446
453
if ( ! fs . existsSync ( pathname ) ) {
447
454
fs . mkdirSync ( pathname ) ;
@@ -500,7 +507,7 @@ const registerRendererEventHandlers = (mainWindow, watcher, lastOpenedCollection
500
507
501
508
ipcMain . handle ( 'renderer:import-collection' , async ( event , collection , collectionLocation ) => {
502
509
try {
503
- let collectionName = sanitizeDirectoryName ( collection . name ) ;
510
+ let collectionName = sanitizeCollectionName ( collection . name ) ;
504
511
let collectionPath = path . join ( collectionLocation , collectionName ) ;
505
512
506
513
if ( fs . existsSync ( collectionPath ) ) {
@@ -516,6 +523,7 @@ const registerRendererEventHandlers = (mainWindow, watcher, lastOpenedCollection
516
523
fs . writeFileSync ( filePath , content ) ;
517
524
}
518
525
if ( item . type === 'folder' ) {
526
+ item . name = sanitizeDirectoryName ( item . name ) ;
519
527
const folderPath = path . join ( currentPath , item . name ) ;
520
528
fs . mkdirSync ( folderPath ) ;
521
529
0 commit comments