mirror of
https://github.com/usebruno/bruno.git
synced 2026-06-11 09:51:30 +00:00
fix: prompt variable in URL path incorrectly parsed as query parameter (#7216)
This commit is contained in:
@@ -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];
|
||||
}
|
||||
|
||||
@@ -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', () => {
|
||||
|
||||
Reference in New Issue
Block a user