Skip to content

fix: prompt variable in URL path incorrectly parsed as query parameter#7216

Open
pooja-bruno wants to merge 1 commit intousebruno:mainfrom
pooja-bruno:fix/prompt-variable-breaks-url-params-table
Open

fix: prompt variable in URL path incorrectly parsed as query parameter#7216
pooja-bruno wants to merge 1 commit intousebruno:mainfrom
pooja-bruno:fix/prompt-variable-breaks-url-params-table

Conversation

@pooja-bruno
Copy link
Collaborator

@pooja-bruno pooja-bruno commented Feb 19, 2026

Description

issue: #7204
JIRA

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.

Before
https://github.com/user-attachments/assets/260f0ecb-b999-4e1c-b83e-e30d4267187b

After
https://github.com/user-attachments/assets/10ebe866-085d-440a-a2f2-3d0d197fb437

Summary by CodeRabbit

  • Bug Fixes

    • Improved URL parsing to correctly handle dynamic template variables throughout the URL. Template content is now properly masked during URL analysis, preventing interference with path and query string detection.
  • Tests

    • Added comprehensive test coverage for URL parsing with template variables in various positions, including multiple variables and template content within query parameters.

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Feb 19, 2026

Walkthrough

The splitOnFirst utility function is enhanced to handle template variables ({{...}}) by masking their contents before delimiter detection. This prevents template variable syntax from interfering with URL parsing logic. Corresponding test cases validate this behavior across multiple scenarios.

Changes

Cohort / File(s) Summary
URL Utility Enhancement
packages/bruno-app/src/utils/url/index.js
Modified splitOnFirst to mask template variable contents ({{...}}) with underscores before searching for delimiters, ensuring delimiter indices are calculated correctly on the masked string.
Test Coverage
packages/bruno-app/src/utils/url/index.spec.js
Added three new test cases validating delimiter handling inside template variables, multiple template variables, and template variables within query parameter values.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

Possibly related PRs

  • usebruno/bruno#6680: Implements the same template variable masking approach for URL/delimiter processing.

Suggested labels

size/S

Suggested reviewers

  • helloanoop
  • lohit-bruno
  • naman-bruno

Poem

🎭 Curly braces once broke the URL split,
But now they're masked—no more parsing grit,
Template variables hide in a disguise,
Delimiters found with correct eyes, 🎯

🚥 Pre-merge checks | ✅ 3
✅ Passed checks (3 passed)
Check name Status Explanation
Title check ✅ Passed The title accurately describes the main change: fixing an issue where prompt variables in URL paths were being incorrectly parsed as query parameters.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.

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

✨ Finishing Touches
  • 📝 Generate docstrings
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment

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
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/utils/url/index.spec.js (1)

290-315: Add an edge case: delimiter exists only inside template variable(s).

The three new tests all have a real ? outside the template variable. There's no test for the case where ? appears only inside {{...}}—which is where the masking logic's index === -1 branch becomes load-bearing after this change. Without it, a regression that over-eagerly matches and assigns index != -1 would go undetected.

🧪 Suggested additional test
   it('should handle prompt variable in query param value', () => {
     const url = 'https://example.com/api?token={{?token}}&active=true';
     const params = splitOnFirst(url, '?');
     expect(params).toEqual([
       'https://example.com/api',
       'token={{?token}}&active=true'
     ]);
   });
+
+  it('should return full URL when ? only exists inside template variable', () => {
+    const url = 'https://example.com/{{?resource}}';
+    const params = splitOnFirst(url, '?');
+    expect(params).toEqual(['https://example.com/{{?resource}}']);
+  });
 });
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@packages/bruno-app/src/utils/url/index.spec.js` around lines 290 - 315, Add a
unit test that covers the edge case where the only occurrences of the delimiter
'?' are inside template variables so the masking logic must return "no split"
(exercise the index === -1 branch). For function splitOnFirst, add a case like
url = 'https://example.com/domain/{{?domain_id}}' and assert splitOnFirst(url,
'?') returns [url, ''] (i.e., the entire string as the first element and an
empty second element), ensuring we detect regressions that accidentally treat
masked '?' as a real delimiter.
🤖 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/utils/url/index.spec.js`:
- Around line 290-315: Add a unit test that covers the edge case where the only
occurrences of the delimiter '?' are inside template variables so the masking
logic must return "no split" (exercise the index === -1 branch). For function
splitOnFirst, add a case like url = 'https://example.com/domain/{{?domain_id}}'
and assert splitOnFirst(url, '?') returns [url, ''] (i.e., the entire string as
the first element and an empty second element), ensuring we detect regressions
that accidentally treat masked '?' as a real delimiter.

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.

1 participant

Comments