forked from extern/bruno
Merge pull request #242 from tpyle/bug/handle-collection-names-with-slashes
Corrects issue when collection names in imports have slashes
This commit is contained in:
commit
626d925ad6
42
.github/workflows/unit-tests.yml
vendored
42
.github/workflows/unit-tests.yml
vendored
@ -1,29 +1,31 @@
|
||||
name: Unit Tests
|
||||
on:
|
||||
push:
|
||||
branches: [ main ]
|
||||
branches: [main]
|
||||
pull_request:
|
||||
branches: [ main ]
|
||||
branches: [main]
|
||||
jobs:
|
||||
test:
|
||||
timeout-minutes: 60
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- uses: actions/checkout@v3
|
||||
- uses: actions/setup-node@v3
|
||||
with:
|
||||
node-version: 16
|
||||
- name: Install dependencies
|
||||
run: npm i --legacy-peer-deps
|
||||
- name: Test Package bruno-query
|
||||
run: npm run test --workspace=packages/bruno-query
|
||||
- name: Build Package bruno-query
|
||||
run: npm run build --workspace=packages/bruno-query
|
||||
- name: Test Package bruno-lang
|
||||
run: npm run test --workspace=packages/bruno-lang
|
||||
- name: Test Package bruno-schema
|
||||
run: npm run test --workspace=packages/bruno-schema
|
||||
- name: Test Package bruno-app
|
||||
run: npm run test --workspace=packages/bruno-app
|
||||
- name: Test Package bruno-js
|
||||
run: npm run test --workspace=packages/bruno-js
|
||||
- uses: actions/checkout@v3
|
||||
- uses: actions/setup-node@v3
|
||||
with:
|
||||
node-version: 16
|
||||
- name: Install dependencies
|
||||
run: npm i --legacy-peer-deps
|
||||
- name: Test Package bruno-query
|
||||
run: npm run test --workspace=packages/bruno-query
|
||||
- name: Build Package bruno-query
|
||||
run: npm run build --workspace=packages/bruno-query
|
||||
- name: Test Package bruno-lang
|
||||
run: npm run test --workspace=packages/bruno-lang
|
||||
- name: Test Package bruno-schema
|
||||
run: npm run test --workspace=packages/bruno-schema
|
||||
- name: Test Package bruno-app
|
||||
run: npm run test --workspace=packages/bruno-app
|
||||
- name: Test Package bruno-js
|
||||
run: npm run test --workspace=packages/bruno-js
|
||||
- name: Test Package bruno-electron
|
||||
run: npm run test --workspace=packages/bruno-electron
|
||||
|
@ -11,7 +11,8 @@ const {
|
||||
isDirectory,
|
||||
browseDirectory,
|
||||
createDirectory,
|
||||
searchForBruFiles
|
||||
searchForBruFiles,
|
||||
sanitizeDirectoryName
|
||||
} = require('../utils/filesystem');
|
||||
const { stringifyJson } = require('../utils/common');
|
||||
const { openCollectionDialog, openCollection } = require('../app/collections');
|
||||
@ -315,7 +316,7 @@ const registerRendererEventHandlers = (mainWindow, watcher, lastOpenedCollection
|
||||
|
||||
ipcMain.handle('renderer:import-collection', async (event, collection, collectionLocation) => {
|
||||
try {
|
||||
let collectionName = collection.name;
|
||||
let collectionName = sanitizeDirectoryName(collection.name);
|
||||
let collectionPath = path.join(collectionLocation, collectionName);
|
||||
|
||||
if (fs.existsSync(collectionPath)) {
|
||||
@ -359,7 +360,7 @@ const registerRendererEventHandlers = (mainWindow, watcher, lastOpenedCollection
|
||||
const uid = generateUidBasedOnHash(collectionPath);
|
||||
const brunoConfig = {
|
||||
version: '1',
|
||||
name: collection.name,
|
||||
name: collectionName,
|
||||
type: 'collection'
|
||||
};
|
||||
const content = await stringifyJson(brunoConfig);
|
||||
|
@ -114,6 +114,10 @@ const searchForBruFiles = (dir) => {
|
||||
return searchForFiles(dir, '.bru');
|
||||
};
|
||||
|
||||
const sanitizeDirectoryName = (name) => {
|
||||
return name.replace(/[<>:"/\\|?*\x00-\x1F]+/g, '-');
|
||||
};
|
||||
|
||||
module.exports = {
|
||||
isValidPathname,
|
||||
exists,
|
||||
@ -127,5 +131,6 @@ module.exports = {
|
||||
createDirectory,
|
||||
browseDirectory,
|
||||
searchForFiles,
|
||||
searchForBruFiles
|
||||
searchForBruFiles,
|
||||
sanitizeDirectoryName
|
||||
};
|
||||
|
26
packages/bruno-electron/src/utils/filesystem.test.js
Normal file
26
packages/bruno-electron/src/utils/filesystem.test.js
Normal file
@ -0,0 +1,26 @@
|
||||
const { sanitizeDirectoryName } = require('./filesystem.js');
|
||||
|
||||
describe('sanitizeDirectoryName', () => {
|
||||
it('should replace invalid characters with hyphens', () => {
|
||||
const input = '<>:"/\\|?*\x00-\x1F';
|
||||
const expectedOutput = '---';
|
||||
expect(sanitizeDirectoryName(input)).toEqual(expectedOutput);
|
||||
});
|
||||
|
||||
it('should not modify valid directory names', () => {
|
||||
const input = 'my-directory';
|
||||
expect(sanitizeDirectoryName(input)).toEqual(input);
|
||||
});
|
||||
|
||||
it('should replace multiple invalid characters with a single hyphen', () => {
|
||||
const input = 'my<>invalid?directory';
|
||||
const expectedOutput = 'my-invalid-directory';
|
||||
expect(sanitizeDirectoryName(input)).toEqual(expectedOutput);
|
||||
});
|
||||
|
||||
it('should handle names with slashes', () => {
|
||||
const input = 'my/invalid/directory';
|
||||
const expectedOutput = 'my-invalid-directory';
|
||||
expect(sanitizeDirectoryName(input)).toEqual(expectedOutput);
|
||||
});
|
||||
});
|
Loading…
Reference in New Issue
Block a user