diff --git a/packages/bruno-app/src/utils/url/index.js b/packages/bruno-app/src/utils/url/index.js index d84451bf9..335351422 100644 --- a/packages/bruno-app/src/utils/url/index.js +++ b/packages/bruno-app/src/utils/url/index.js @@ -73,7 +73,10 @@ export const splitOnFirst = (str, char) => { return [str]; } - let index = str.indexOf(char); + // Mask {{ }} template variables so their contents don't interfere with the search + const masked = str.replace(/\{\{.*?\}\}/g, (match) => '_'.repeat(match.length)); + const index = masked.indexOf(char); + if (index === -1) { return [str]; } diff --git a/packages/bruno-app/src/utils/url/index.spec.js b/packages/bruno-app/src/utils/url/index.spec.js index 92fecb523..cd546cc95 100644 --- a/packages/bruno-app/src/utils/url/index.spec.js +++ b/packages/bruno-app/src/utils/url/index.spec.js @@ -286,6 +286,33 @@ describe('Url Utils - splitOnFirst', () => { const params = splitOnFirst('a=1&b=2', '&'); expect(params).toEqual(['a=1', 'b=2']); }); + + it('should skip ? inside {{ }} template variables', () => { + const url = 'https://example.com/domain/{{?domain_id}}?include_dcv=true&include_validation=true'; + const params = splitOnFirst(url, '?'); + expect(params).toEqual([ + 'https://example.com/domain/{{?domain_id}}', + 'include_dcv=true&include_validation=true' + ]); + }); + + it('should handle multiple prompt variables in URL path', () => { + const url = 'http://localhost:{{?port}}/api/{{?resource}}?key=value'; + const params = splitOnFirst(url, '?'); + expect(params).toEqual([ + 'http://localhost:{{?port}}/api/{{?resource}}', + 'key=value' + ]); + }); + + it('should handle prompt variable in query param value', () => { + const url = 'https://example.com/api?token={{?token}}&active=true'; + const params = splitOnFirst(url, '?'); + expect(params).toEqual([ + 'https://example.com/api', + 'token={{?token}}&active=true' + ]); + }); }); describe('Url Utils - interpolateUrl, interpolateUrlPathParams', () => {