mirror of
https://github.com/usebruno/bruno.git
synced 2026-06-11 09:51:30 +00:00
fix: "URL encoding off" ignored for multi-param URLs in generated code (#7769)
This commit is contained in:
@@ -88,7 +88,7 @@ const generateSnippet = ({ language, item, collection, shouldInterpolate = false
|
||||
const settings = item.draft ? get(item, 'draft.settings') : get(item, 'settings');
|
||||
const rawUrl = item.rawUrl || request.url;
|
||||
const parsed = parse(request.url, true, true);
|
||||
const search = stringify(parsed.query);
|
||||
const search = stringify(parsed.query, { sort: false });
|
||||
const httpSnippetPath = search ? `${parsed.pathname}?${search}` : parsed.pathname;
|
||||
|
||||
let desiredPath;
|
||||
|
||||
@@ -919,7 +919,7 @@ describe('generateSnippet – encodeUrl setting', () => {
|
||||
if (!parsed.query || Object.keys(parsed.query).length === 0) {
|
||||
return parsed.pathname;
|
||||
}
|
||||
const search = stringify(parsed.query);
|
||||
const search = stringify(parsed.query, { sort: false });
|
||||
return search ? `${parsed.pathname}?${search}` : parsed.pathname;
|
||||
};
|
||||
|
||||
@@ -1240,4 +1240,28 @@ describe('generateSnippet – encodeUrl setting', () => {
|
||||
const result = generateSnippet({ language, item, collection: baseCollection, shouldInterpolate: false });
|
||||
expect(result).toBe(`curl -X GET '${rawUrl}'`);
|
||||
});
|
||||
|
||||
it('should preserve raw URL with multiple query params in non-alphabetical order when encodeUrl is false', () => {
|
||||
const rawUrl = 'https://example.com/api?start=2026-02-01T00:00:00.000Z&a=b';
|
||||
const item = makeItem(rawUrl, { encodeUrl: false });
|
||||
|
||||
const result = generateSnippet({ language, item, collection: baseCollection, shouldInterpolate: false });
|
||||
expect(result).toBe(`curl -X GET '${rawUrl}'`);
|
||||
});
|
||||
|
||||
it('should encode URL with multiple query params in non-alphabetical order when encodeUrl is true', () => {
|
||||
const rawUrl = 'https://example.com/api?start=2026-02-01T00:00:00.000Z&a=b';
|
||||
const item = makeItem(rawUrl, { encodeUrl: true });
|
||||
|
||||
const result = generateSnippet({ language, item, collection: baseCollection, shouldInterpolate: false });
|
||||
expect(result).toBe('curl -X GET \'https://example.com/api?start=2026-02-01T00%3A00%3A00.000Z&a=b\'');
|
||||
});
|
||||
|
||||
it('should preserve param order in raw URL when encodeUrl is false and params are reverse-alphabetical', () => {
|
||||
const rawUrl = 'https://example.com/api?z=last&a=first&m=middle';
|
||||
const item = makeItem(rawUrl, { encodeUrl: false });
|
||||
|
||||
const result = generateSnippet({ language, item, collection: baseCollection, shouldInterpolate: false });
|
||||
expect(result).toBe(`curl -X GET '${rawUrl}'`);
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user