forked from extern/bruno
fix: fixed issue where postman collection import was failing when the filename had / or ? chars (#147)
This commit is contained in:
parent
86094cc054
commit
b6528062f0
@ -49,3 +49,15 @@ export const safeStringifyJSON = (obj, indent=false) => {
|
||||
return obj;
|
||||
}
|
||||
}
|
||||
|
||||
// Remove any characters that are not alphanumeric, spaces, hyphens, or underscores
|
||||
export const normalizeFileName = (name) => {
|
||||
if (!name) {
|
||||
return name;
|
||||
}
|
||||
|
||||
const validChars = /[^\w\s-]/g;
|
||||
const formattedName = name.replace(validChars, '-');
|
||||
|
||||
return formattedName;
|
||||
}
|
||||
|
19
packages/bruno-app/src/utils/common/index.spec.js
Normal file
19
packages/bruno-app/src/utils/common/index.spec.js
Normal file
@ -0,0 +1,19 @@
|
||||
const { describe, it, expect } = require("@jest/globals");
|
||||
|
||||
import { normalizeFileName } from './index';
|
||||
|
||||
describe("common utils", () => {
|
||||
describe("normalizeFileName", () => {
|
||||
it("should remove special characters", () => {
|
||||
expect(normalizeFileName("hello world")).toBe("hello world");
|
||||
expect(normalizeFileName("hello-world")).toBe("hello-world");
|
||||
expect(normalizeFileName("hello_world")).toBe("hello_world");
|
||||
expect(normalizeFileName("hello_world-")).toBe("hello_world-");
|
||||
expect(normalizeFileName("hello_world-123")).toBe("hello_world-123");
|
||||
expect(normalizeFileName("hello_world-123!@#$%^&*()")).toBe("hello_world-123----------");
|
||||
expect(normalizeFileName("hello_world?")).toBe("hello_world-");
|
||||
expect(normalizeFileName("foo/bar/")).toBe("foo-bar-");
|
||||
expect(normalizeFileName("foo\\bar\\")).toBe("foo-bar-");
|
||||
});
|
||||
});
|
||||
});
|
@ -3,7 +3,7 @@ import each from 'lodash/each';
|
||||
import get from 'lodash/get';
|
||||
|
||||
import cloneDeep from 'lodash/cloneDeep';
|
||||
import { uuid } from 'utils/common';
|
||||
import { uuid, normalizeFileName } from 'utils/common';
|
||||
import { isItemARequest } from 'utils/collections';
|
||||
import { collectionSchema } from '@usebruno/schema';
|
||||
import { BrunoError } from 'utils/common/error';
|
||||
@ -63,6 +63,8 @@ export const updateUidsInCollection = (_collection) => {
|
||||
export const transformItemsInCollection = (collection) => {
|
||||
const transformItems = (items = []) => {
|
||||
each(items, (item) => {
|
||||
item.name = normalizeFileName(item.name);
|
||||
|
||||
if (['http', 'graphql'].includes(item.type)) {
|
||||
item.type = `${item.type}-request`;
|
||||
if(item.request.query) {
|
||||
|
Loading…
Reference in New Issue
Block a user