mirror of
https://github.com/usebruno/bruno.git
synced 2026-06-27 14:44:07 +00:00
chore: base format (#5624)
This commit is contained in:
committed by
GitHub
parent
6f8c543ee3
commit
c15d47c0dc
@@ -35,7 +35,7 @@ export const parsePathParams = (url) => {
|
||||
// Enhanced: also match :param inside parentheses and/or quotes
|
||||
const paramRegex = /[:](\w+)/g;
|
||||
const foundParams = new Set();
|
||||
paths.forEach((segment) => {
|
||||
paths.forEach(segment => {
|
||||
let match;
|
||||
while ((match = paramRegex.exec(segment))) {
|
||||
if (match[1]) {
|
||||
@@ -49,7 +49,7 @@ export const parsePathParams = (url) => {
|
||||
}
|
||||
}
|
||||
});
|
||||
return Array.from(foundParams).map((name) => ({ name, value: '' }));
|
||||
return Array.from(foundParams).map(name => ({ name, value: '' }));
|
||||
};
|
||||
|
||||
export const splitOnFirst = (str, char) => {
|
||||
@@ -89,7 +89,7 @@ export const interpolateUrlPathParams = (url, params) => {
|
||||
.split('/')
|
||||
.map((segment) => {
|
||||
|
||||
if(!segment.startsWith(":")) return segment
|
||||
if (!segment.startsWith(':')) return segment;
|
||||
|
||||
let match;
|
||||
while ((match = regex.exec(segment))) {
|
||||
@@ -99,7 +99,7 @@ export const interpolateUrlPathParams = (url, params) => {
|
||||
// Remove leading quotes/parentheses if present
|
||||
name = name.replace(/^[('"`]+/, '');
|
||||
if (name) {
|
||||
const pathParam = params.find((p) => p?.name === name && p?.type === 'path');
|
||||
const pathParam = params.find(p => p?.name === name && p?.type === 'path');
|
||||
return pathParam ? pathParam.value : segment;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -45,28 +45,28 @@ describe('Url Utils - parsePathParams', () => {
|
||||
});
|
||||
|
||||
it('should parse path param inside parentheses and quotes', () => {
|
||||
const params = parsePathParams("https://example.com/ExchangeRates(':ExchangeRateOID')");
|
||||
const params = parsePathParams('https://example.com/ExchangeRates(\':ExchangeRateOID\')');
|
||||
expect(params).toEqual([{ name: 'ExchangeRateOID', value: '' }]);
|
||||
});
|
||||
|
||||
it('should parse path param inside parentheses and no quotes', () => {
|
||||
const params = parsePathParams("https://example.com/ExchangeRates(:ExchangeRateOID)");
|
||||
const params = parsePathParams('https://example.com/ExchangeRates(:ExchangeRateOID)');
|
||||
expect(params).toEqual([{ name: 'ExchangeRateOID', value: '' }]);
|
||||
});
|
||||
|
||||
it('should parse multiple path params inside parentheses', () => {
|
||||
const params = parsePathParams("https://example.com/Exchange(:ExchangeId)/ExchangeRates(:ExchangeRateOID)");
|
||||
const params = parsePathParams('https://example.com/Exchange(:ExchangeId)/ExchangeRates(:ExchangeRateOID)');
|
||||
expect(params).toEqual([{ name: 'ExchangeId', value: '' }, { name: 'ExchangeRateOID', value: '' }]);
|
||||
});
|
||||
|
||||
it('should parse mix and match of normal and param inside parentheses', () => {
|
||||
const params = parsePathParams("https://example.com/Exchange(:ExchangeId)/:key");
|
||||
const params = parsePathParams('https://example.com/Exchange(:ExchangeId)/:key');
|
||||
expect(params).toEqual([{ name: 'ExchangeId', value: '' }, { name: 'key', value: '' }]);
|
||||
});
|
||||
|
||||
// OData-specific test cases for enhanced path parameter parsing
|
||||
it('should parse OData entity key with single quotes', () => {
|
||||
const params = parsePathParams("https://example.com/odata/Products(':productId')");
|
||||
const params = parsePathParams('https://example.com/odata/Products(\':productId\')');
|
||||
expect(params).toEqual([{ name: 'productId', value: '' }]);
|
||||
});
|
||||
|
||||
|
||||
@@ -91,14 +91,14 @@ const interpolateVars = (request, envVariables = {}, runtimeVariables = {}, proc
|
||||
if (typeof request.data === 'string') {
|
||||
if (request.data.length) {
|
||||
request.data = _interpolate(request.data, {
|
||||
escapeJSONStrings: true
|
||||
escapeJSONStrings: true,
|
||||
});
|
||||
}
|
||||
} else if (typeof request.data === 'object') {
|
||||
try {
|
||||
const jsonDoc = JSON.stringify(request.data);
|
||||
const parsed = _interpolate(jsonDoc, {
|
||||
escapeJSONStrings: true
|
||||
escapeJSONStrings: true,
|
||||
});
|
||||
request.data = JSON.parse(parsed);
|
||||
} catch (err) {}
|
||||
|
||||
@@ -163,25 +163,24 @@ describe('interpolate-vars: interpolateVars', () => {
|
||||
{
|
||||
type: 'path',
|
||||
name: 'CategoryID',
|
||||
value: 'foobar'
|
||||
value: 'foobar',
|
||||
},
|
||||
{
|
||||
type: 'path',
|
||||
name: 'ItemId',
|
||||
value: 1
|
||||
value: 1,
|
||||
},
|
||||
{
|
||||
type: 'path',
|
||||
name: 'xpath',
|
||||
value: 'foobar'
|
||||
}
|
||||
]
|
||||
value: 'foobar',
|
||||
},
|
||||
],
|
||||
};
|
||||
|
||||
const result = interpolateVars(request, null, null, null);
|
||||
expect(result.url).toBe('http://example.com/Category(\'foobar\')/Item(1)/foobar/Tags(%22tag%20test%22)');
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
describe('With process environment variables', () => {
|
||||
|
||||
Reference in New Issue
Block a user