fix: "URL encoding off" ignored for multi-param URLs in generated code (#7769)

This commit is contained in:
prateek-bruno
2026-04-28 19:13:52 +05:30
committed by GitHub
parent a688effe67
commit ff6ec4a689
2 changed files with 26 additions and 2 deletions

View File

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

View File

@@ -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}'`);
});
});