fix: prompt variable in URL path incorrectly parsed as query parameter (#7216)

This commit is contained in:
Pooja
2026-03-27 15:47:21 +05:30
committed by GitHub
parent 35cd72534b
commit 9cea60477a
2 changed files with 31 additions and 1 deletions

View File

@@ -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];
}

View File

@@ -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', () => {