Skip to content

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

Open
prateek-bruno wants to merge 2 commits intousebruno:mainfrom
prateek-bruno:fix-url-encoding-in-curl
Open

fix: "URL encoding off" ignored for multi-param URLs in generated code#7769
prateek-bruno wants to merge 2 commits intousebruno:mainfrom
prateek-bruno:fix-url-encoding-in-curl

Conversation

@prateek-bruno
Copy link
Copy Markdown

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

Description

Fixes #7524

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 the original URL query parameter order instead of sorting them, so snippets match the original request sequence.
    • Query value encoding respects the encodeUrl setting, ensuring encoded or raw parameter values appear as expected.
  • Tests

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

@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai Bot commented Apr 15, 2026

Walkthrough

Changed query-string serialization in the snippet generator to call stringify(parsed.query, { sort: false }), preserving original query parameter order when constructing the HTTP snippet path; corresponding test expectations were updated/added to reflect ordering and encoding behavior.

Changes

Cohort / File(s) Summary
Snippet generator
packages/bruno-app/src/components/Sidebar/Collections/Collection/CollectionItem/GenerateCodeItem/utils/snippet-generator.js
Replace stringify(parsed.query) with stringify(parsed.query, { sort: false }) to preserve original query parameter order when building httpSnippetPath.
Tests / Expectations
packages/bruno-app/src/components/Sidebar/Collections/Collection/CollectionItem/GenerateCodeItem/utils/snippet-generator.spec.js
Update helper to call stringify(..., { sort: false }); add/adjust tests for generateSnippet covering encodeUrl behavior and query ordering/encoding expectations.

Estimated Code Review Effort

🎯 2 (Simple) | ⏱️ ~10 minutes

Possibly related PRs

Suggested labels

size/XS

Suggested reviewers

  • helloanoop
  • lohit-bruno
  • naman-bruno
  • bijin-bruno

Poem

A tiny tweak to how queries align,
The order kept, each param in line.
Tests updated to prove the case,
Snippets now mirror the original trace. ✨

🚥 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 summarizes the main fix: addressing URL encoding being ignored for multi-parameter URLs in generated code snippets.
Linked Issues check ✅ Passed The PR fix directly addresses issue #7524 by preserving query parameter order via { sort: false }, enabling the encodeUrl setting to work correctly for multi-parameter URLs.
Out of Scope Changes check ✅ Passed All changes are scoped to snippet generation logic and corresponding tests; 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.

Copy link
Copy Markdown
Contributor

@coderabbitai coderabbitai Bot left a comment

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

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

1 participant