fix: update regex for path parameter parsing to handle alphanumeric and underscore characters (#7388)

This commit is contained in:
Abhishek S Lal
2026-03-27 20:03:00 +05:30
committed by GitHub
parent 13e97f0367
commit f1b84e09c3
4 changed files with 18 additions and 4 deletions

View File

@@ -53,7 +53,7 @@ export const parsePathParams = (url) => {
return;
}
const paramRegex = /[:](\w+)/g;
const paramRegex = /[:]([a-zA-Z_]\w*)/g;
let match;
while ((match = paramRegex.exec(segment))) {
if (!match[1]) continue;
@@ -131,7 +131,7 @@ export const interpolateUrlPathParams = (url, params, variables = {}, options =
return segment;
}
const regex = /[:](\w+)/g;
const regex = /[:]([a-zA-Z_]\w*)/g;
let match;
let result = segment;
while ((match = regex.exec(segment))) {

View File

@@ -156,6 +156,20 @@ describe('Url Utils - parsePathParams', () => {
expect(params).toEqual([]);
});
it('should NOT treat colons in datetime values as path parameters', () => {
const params = parsePathParams(
'https://api10.successfactors.com/odata/v2/EmpJob(seqNumber=1L,startDate=datetime\'2021-08-29T00:00:00\',userId=\'213668\')'
);
expect(params).toEqual([]);
});
it('should still parse named path params in OData segments with datetime values', () => {
const params = parsePathParams(
'https://example.com/odata/EmpJob(startDate=datetime\'2021-08-29T00:00:00\',userId=:userId)'
);
expect(params).toEqual([{ name: 'userId', value: '' }]);
});
it('should NOT treat embedded colons as path parameters (regression fix)', () => {
// This test case reproduces the bug reported in issue #5805
const params = parsePathParams('/start/1:2:AHLS-HASD/form');

View File

@@ -147,7 +147,7 @@ const interpolateVars = (request, envVariables = {}, runtimeVariables = {}, proc
// 2. EntitySet(Key1=value1,Key2=value2)
// 3. Function(param=value)
if (/^[A-Za-z0-9_.-]+\([^)]*\)$/.test(path)) {
const paramRegex = /[:](\w+)/g;
const paramRegex = /[:]([a-zA-Z_]\w*)/g;
let match;
let result = path;
while ((match = paramRegex.exec(path))) {

View File

@@ -184,7 +184,7 @@ const interpolateVars = (request, envVariables = {}, runtimeVariables = {}, proc
// 2. EntitySet(Key1=value1,Key2=value2)
// 3. Function(param=value)
if (/^[A-Za-z0-9_.-]+\([^)]*\)$/.test(path)) {
const paramRegex = /[:](\w+)/g;
const paramRegex = /[:]([a-zA-Z_]\w*)/g;
let match;
let result = path;
while ((match = paramRegex.exec(path))) {