diff --git a/packages/bruno-app/src/utils/url/index.js b/packages/bruno-app/src/utils/url/index.js index f6feff0a0..f9557b3c4 100644 --- a/packages/bruno-app/src/utils/url/index.js +++ b/packages/bruno-app/src/utils/url/index.js @@ -18,16 +18,17 @@ const hasLength = (str) => { }; export const parseQueryParams = (query) => { - if (!query || !query.length) { + try { + if (!query || !query.length) { + return []; + } + + return Array.from(new URLSearchParams(query.split('#')[0]).entries()) + .map(([name, value]) => ({ name, value })); + } catch (error) { + console.error('Error parsing query params:', error); return []; } - - let params = query.split('&').map((param) => { - let [name, value = ''] = param.split('='); - return { name, value }; - }); - - return filter(params, (p) => hasLength(p.name)); }; export const parsePathParams = (url) => { diff --git a/packages/bruno-app/src/utils/url/index.spec.js b/packages/bruno-app/src/utils/url/index.spec.js index 59d50043c..0645befee 100644 --- a/packages/bruno-app/src/utils/url/index.spec.js +++ b/packages/bruno-app/src/utils/url/index.spec.js @@ -49,6 +49,23 @@ describe('Url Utils - parseQueryParams', () => { { name: 'b', value: '2' } ]); }); + + it('should parse query with "=" character - case 9', () => { + const params = parseQueryParams('a=1&b={color=red,size=large}&c=3'); + expect(params).toEqual([ + { name: 'a', value: '1' }, + { name: 'b', value: '{color=red,size=large}' }, + { name: 'c', value: '3' } + ]); + }); + + it('should parse query with fragment - case 10', () => { + const params = parseQueryParams('a=1&b=2#I-AM-FRAGMENT'); + expect(params).toEqual([ + { name: 'a', value: '1' }, + { name: 'b', value: '2' } + ]); + }); }); describe('Url Utils - parsePathParams', () => {