Skip to content

fix: URL query parsing when values contain '='#7061

Open
vmridul wants to merge 1 commit intoRocketChat:developfrom
vmridul:fix/parseQuery
Open

fix: URL query parsing when values contain '='#7061
vmridul wants to merge 1 commit intoRocketChat:developfrom
vmridul:fix/parseQuery

Conversation

@vmridul
Copy link
Copy Markdown

@vmridul vmridul commented Mar 24, 2026

This PR fixes a bug where URL query values could be cut off when they contained =

Example:
parseQuery('host=open.rocket.chat&token=abc==&type=auth')

Before:
{ host: 'open.rocket.chat', token: 'abc', type: 'auth' }

After:
{ host: 'open.rocket.chat', token: 'abc==', type: 'auth' }

I updated parseQuery to split only on the first =

I also added tests for these cases:

  • a query value like token=abc== because that was the broken case
  • an encoded URL value to make sure values with encoded = and + still decode correctly

Types of changes

  • Bugfix (non-breaking change which fixes an issue)
  • Improvement (non-breaking change which improves a current function)
  • New feature (non-breaking change which adds functionality)
  • Documentation update (if none of the other choices apply)

Checklist

  • I have read the CONTRIBUTING doc
  • I have signed the CLA
  • Lint and unit tests pass locally with my changes
  • I have added tests that prove my fix is effective or that my feature works (if applicable)
  • I have added necessary documentation (if applicable)
  • Any dependent changes have been merged and published in downstream modules

Summary by CodeRabbit

  • Bug Fixes

    • Improved query parameter parsing to correctly handle values containing = characters and properly decode + signs and percent-encoded characters.
  • Tests

    • Added comprehensive test coverage for query parameter parsing edge cases.

@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai bot commented Mar 24, 2026

Walkthrough

A query string parsing utility was updated to correctly handle parameters containing multiple = characters by using indexOf() instead of split(), ensuring the entire substring after the first = is treated as the value. Corresponding test cases verify the fix handles various encoding scenarios.

Changes

Cohort / File(s) Summary
Query Parsing Logic
app/lib/methods/helpers/parseQuery.ts
Changed parameter splitting strategy from split('=') to indexOf('=') to preserve multiple = characters within values. Parameters without = now produce empty string values.
Query Parsing Tests
app/lib/methods/helpers/parseQuery.test.ts
Added test suite with two assertions verifying correct handling of values containing = characters and proper decoding of + signs and percent-encoded characters.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

Suggested labels

type: bug

🚥 Pre-merge checks | ✅ 3
✅ Passed checks (3 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title 'fix: URL query parsing when values contain "=" ' directly and specifically describes the main bug being fixed—a parsing issue where query values containing '=' characters were being incorrectly truncated.
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.


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)
app/lib/methods/helpers/parseQuery.test.ts (1)

3-18: Optional: add one test for params without =.

Since parseQuery now explicitly branches for separatorIndex < 0, a case like flag&token=abc== would make that path regression-safe too.

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@app/lib/methods/helpers/parseQuery.test.ts` around lines 3 - 18, Add a unit
test for parseQuery covering a parameter with no "=" (e.g., "flag&token=abc==")
to exercise the separatorIndex < 0 branch; verify that parseQuery returns an
object including the flag key with the expected empty-string value (or the
implementation's chosen sentinel) and that the token value remains "abc==",
using the parseQuery test suite where other cases live.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Nitpick comments:
In `@app/lib/methods/helpers/parseQuery.test.ts`:
- Around line 3-18: Add a unit test for parseQuery covering a parameter with no
"=" (e.g., "flag&token=abc==") to exercise the separatorIndex < 0 branch; verify
that parseQuery returns an object including the flag key with the expected
empty-string value (or the implementation's chosen sentinel) and that the token
value remains "abc==", using the parseQuery test suite where other cases live.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 22ca5fae-0a82-495b-9a02-a3d7559709e2

📥 Commits

Reviewing files that changed from the base of the PR and between 115fa79 and d034090.

📒 Files selected for processing (2)
  • app/lib/methods/helpers/parseQuery.test.ts
  • app/lib/methods/helpers/parseQuery.ts
📜 Review details
🔇 Additional comments (2)
app/lib/methods/helpers/parseQuery.test.ts (1)

4-17: Good regression coverage for this fix.

The assertions on Line 5 and Line 13 correctly lock the bugfix behavior (token=abc==) and the decode behavior for +/encoded values.

app/lib/methods/helpers/parseQuery.ts (1)

18-20: Correct fix: split only on the first =.

Using indexOf + slice on Line 18-Line 20 resolves truncation for values like abc== while still handling params without = safely.

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

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant