Skip to content

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

Merged
sid-bruno merged 3 commits into
usebruno:mainfrom
prateek-bruno:fix-url-encoding-in-curl
Apr 28, 2026
Merged

fix: "URL encoding off" ignored for multi-param URLs in generated code#7769
sid-bruno merged 3 commits into
usebruno:mainfrom
prateek-bruno:fix-url-encoding-in-curl

Conversation

@prateek-bruno

@prateek-bruno prateek-bruno commented Apr 15, 2026

Copy link
Copy Markdown
Collaborator

Description

Fixes #7524
BRU-3158

Root cause
In snippet-generator.js, we compute httpSnippetPath via query-string's stringify, then replaceAll it with the raw URL when encoding is off. stringify sorts keys alphabetically by default, so the predicted string (a=b&start=...) no longer matches HTTPSnippet's actual output (start=...&a=b), replaceAll silently no-ops and the encoded URL remains. With a single param there's nothing to sort, which is why the bug was masked.

Fix
One-line change: pass { sort: false } to stringify so param order is preserved.

After:
Screenshot 2026-04-15 at 4 01 56â€ŊPM

Before:
Screenshot 2026-04-15 at 4 02 25â€ŊPM

Contribution Checklist:

  • I've used AI significantly to create this pull request
  • The pull request only addresses one issue or adds one feature.
  • The pull request does not introduce any breaking changes
  • I have added screenshots or gifs to help explain the change if applicable.
  • I have read the contribution guidelines.
  • Create an issue and link to the pull request.

Summary by CodeRabbit

  • Bug Fixes

    • Generated code snippets now preserve original URL query parameter order (no automatic sorting), so snippets match the original request sequence.
    • Query value handling now respects the encodeUrl setting, producing encoded or raw parameter values as expected.
  • Tests

    • Added tests validating parameter ordering and encoding behavior in generated snippets.

@coderabbitai

coderabbitai Bot commented Apr 15, 2026

Copy link
Copy Markdown
Contributor

No actionable comments were generated in the recent review. 🎉

â„đïļ Recent review info
⚙ïļ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: f1793f31-ee8a-42da-b644-24c16f9e39c8

ðŸ“Ĩ Commits

Reviewing files that changed from the base of the PR and between 7b6a892 and 980fdfc.

📒 Files selected for processing (1)
  • packages/bruno-app/src/components/Sidebar/Collections/Collection/CollectionItem/GenerateCodeItem/utils/snippet-generator.spec.js

Walkthrough

Changed query-string serialization in the snippet generator to use stringify(parsed.query, { sort: false }), preserving original query parameter order when building the HTTP snippet path; tests were updated/added to assert ordering and encoding behavior for encodeUrl.

Changes

Cohort / File(s) Summary
Snippet generator
packages/bruno-app/src/components/Sidebar/Collections/Collection/CollectionItem/GenerateCodeItem/utils/snippet-generator.js
Replaced stringify(parsed.query) with stringify(parsed.query, { sort: false }) so generated httpSnippetPath preserves original query parameter order.
Tests / Expectations
packages/bruno-app/src/components/Sidebar/Collections/Collection/CollectionItem/GenerateCodeItem/utils/snippet-generator.spec.js
Updated test helper to use stringify(..., { sort: false }); added/adjusted tests covering generateSnippet with encodeUrl true/false to validate query ordering and colon encoding behavior.

Estimated code review effort

ðŸŽŊ 2 (Simple) | ⏱ïļ ~10 minutes

Suggested labels

size/M

Suggested reviewers

  • helloanoop
  • lohit-bruno
  • bijin-bruno
  • gopu-bruno

Poem

A tiny change that keeps order right,
Queries march on, left to right.
Tests confirm the URL’s song,
Encoded or raw — now nothing’s wrong. âœĻ

ðŸšĨ Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title accurately describes the main change: fixing URL encoding behavior for multi-parameter URLs in generated code snippets.
Linked Issues check ✅ Passed The PR addresses issue #7524 by fixing query parameter order preservation via sort: false, enabling proper URL encoding toggle behavior for multi-param queries.
Out of Scope Changes check ✅ Passed All changes are directly scoped to fixing URL encoding in snippet generation; no unrelated modifications detected.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.

✏ïļ Tip: You can configure your own custom pre-merge checks in the settings.

âœĻ Finishing Touches
🧊 Generate unit tests (beta)
  • Create PR with unit tests

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

âĪïļ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ðŸ§đ Nitpick comments (1)
packages/bruno-app/src/components/Sidebar/Collections/Collection/CollectionItem/GenerateCodeItem/utils/snippet-generator.spec.js (1)

1253-1261: Strengthen this assertion to verify query param order explicitly.

The test title says “non-alphabetical order”, but current checks can still pass if params are reordered. Assert the ordered encoded fragment directly.

Suggested test assertion update
   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).toContain('%3A');
-    expect(result).toContain('start=');
-    expect(result).toContain('a=b');
+    expect(result).toContain('start=2026-02-01T00%3A00%3A00.000Z&a=b');
   });

As per coding guidelines, “Write behaviour-driven tests, not implementation-driven ones” and “Aim for tests that fail usefully.”

ðŸĪ– Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In
`@packages/bruno-app/src/components/Sidebar/Collections/Collection/CollectionItem/GenerateCodeItem/utils/snippet-generator.spec.js`
around lines 1253 - 1261, Update the test case that checks URL encoding order so
it asserts the exact encoded query fragment in order instead of loosely checking
pieces; specifically, in the "should encode URL with multiple query params in
non-alphabetical order when encodeUrl is true" test (using makeItem,
generateSnippet, language, baseCollection), replace the loose
expect(result).toContain checks with a single assertion that the result contains
the exact encoded fragment showing the timestamp encoded and then "&a=b"
(preserving the original non-alphabetical param order), e.g. assert the encoded
"start=..." segment immediately followed by "&a=b".
ðŸĪ– Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Nitpick comments:
In
`@packages/bruno-app/src/components/Sidebar/Collections/Collection/CollectionItem/GenerateCodeItem/utils/snippet-generator.spec.js`:
- Around line 1253-1261: Update the test case that checks URL encoding order so
it asserts the exact encoded query fragment in order instead of loosely checking
pieces; specifically, in the "should encode URL with multiple query params in
non-alphabetical order when encodeUrl is true" test (using makeItem,
generateSnippet, language, baseCollection), replace the loose
expect(result).toContain checks with a single assertion that the result contains
the exact encoded fragment showing the timestamp encoded and then "&a=b"
(preserving the original non-alphabetical param order), e.g. assert the encoded
"start=..." segment immediately followed by "&a=b".

â„đïļ Review info
⚙ïļ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: 3fe9a35c-ba9d-4bb3-b814-3041254a78ff

ðŸ“Ĩ Commits

Reviewing files that changed from the base of the PR and between c1c3121 and 7b6a892.

📒 Files selected for processing (1)
  • packages/bruno-app/src/components/Sidebar/Collections/Collection/CollectionItem/GenerateCodeItem/utils/snippet-generator.spec.js

@pull-request-size pull-request-size Bot added size/S and removed size/M labels Apr 28, 2026
@prateek-bruno

Copy link
Copy Markdown
Collaborator Author

@sid-bruno Have updated the tests!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

URL Encoding setting has no effect on query parameters — colons in param values always encoded by axios

2 participants