Skip to content

Conversation

Anshumancanrock
Copy link

@Anshumancanrock Anshumancanrock commented Sep 16, 2025

Proposed changes (including videos or screenshots)

This PR fixes a bug in the message parser where Markdown links containing unencoded parentheses in URLs were being incorrectly truncated. The issue occurred because the PEG grammar's URLBody rule included opening parentheses ( in its character class but was missing the closing parenthesis ), causing the parser to stop at the first closing parenthesis encountered.

Fixes: #36927

Before this fix:

[link](https://example.com/query?this=(is)&a=problem)

Would be parsed as: https://example.com/query?this=(is (truncated)

After this fix:

[link](https://example.com/query?this=(is)&a=problem)

Is correctly parsed as: https://example.com/query?this=(is)&a=problem (full URL preserved)

Issue(s)

Fixes the issue where links with unencoded parentheses () in URLs are not correctly converted/parsed in Markdown syntax.

Steps to test or reproduce

  1. Create a message with a Markdown link containing unencoded parentheses in the URL:

    [Test Link](https://example.com/query?this=(is)&a=problem)
  2. Verify that the link renders correctly and points to the full URL: https://example.com/query?this=(is)&a=problem

  3. Run the test suite to ensure the new test passes:

    cd packages/message-parser
    npm test
  4. Test edge cases:

    • Multiple parentheses: [link](https://example.com/path/(section)/(subsection))
    • Nested parentheses: [link](https://example.com/path/((nested)))
    • Mixed query parameters: [link](https://example.com/query?param=(value)&other=test)

This is a minimal fix that only adds the missing ) character to the existing URLBody character class in the PEG grammar. The change is surgical and backward-compatible, addressing the specific issue without affecting other parsing behavior. The fix maintains consistency with the existing ( character already present in the character class.

Copy link
Contributor

dionisio-bot bot commented Sep 16, 2025

Looks like this PR is not ready to merge, because of the following issues:

  • This PR is missing the 'stat: QA assured' label
  • This PR is missing the required milestone or project

Please fix the issues and try again

If you have any trouble, please check the PR guidelines

Copy link

changeset-bot bot commented Sep 16, 2025

⚠️ No Changeset found

Latest commit: 2d6bc27

Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.

This PR includes no changesets

When changesets are added to this PR, you'll see the packages that this PR includes changesets for and the associated semver types

Click here to learn what changesets are, and how to add one.

Click here if you're a maintainer who wants to add a changeset to this PR

@CLAassistant
Copy link

CLA assistant check
Thank you for your submission! We really appreciate it. Like many open source projects, we ask that you sign our Contributor License Agreement before we can accept your contribution.
You have signed the CLA already but the status is still pending? Let us recheck it.

Copy link

coderabbitai bot commented Sep 16, 2025

Walkthrough

Updated URL parsing in the PEG grammar to allow closing parentheses within URL bodies and removed an inline comment. Added a test to verify parsing of links whose URLs include parentheses in query strings.

Changes

Cohort / File(s) Summary
Parser grammar update
packages/message-parser/src/grammar.pegjs
Expanded URLBody character set to include ')' inside URLs; removed a TODO comment. No public API changes.
Link parsing tests
packages/message-parser/tests/link.test.ts
Added a test ensuring links with parentheses in query parameters are parsed and preserved in the AST.

Sequence Diagram(s)

sequenceDiagram
  autonumber
  participant MD as Markdown Source
  participant Parser as Message Parser
  participant PEG as PEG Grammar
  participant URL as URLBody Rule

  MD->>Parser: [link](https://example.com/query?this=(is)&a=problem)
  Parser->>PEG: Tokenize and parse
  PEG->>URL: Match URL body characters
  Note over URL: ')' allowed in URL body (updated)
  URL-->>PEG: URL token with parentheses
  PEG-->>Parser: Link node with href and text
  Parser-->>MD: AST (Paragraph -> Link("link"))
Loading

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

Poem

I twitch my whiskers, hop with cheer,
A bracket joins the links this year!
Parentheses now safely glide,
Through query strings they snugly ride.
Parsers parse, tests softly thrum—
Clicky-click, the URLs come.
((Happy hops)) from this bun.

Pre-merge checks and finishing touches

✅ 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: Links with parentheses in URLs not working correctly" is concise, uses a conventional "fix:" prefix, and accurately summarizes the primary change—repairing Markdown link parsing for URLs containing unencoded parentheses—so it clearly communicates the main intent to reviewers and future readers.
Docstring Coverage ✅ Passed No functions found in the changes. Docstring coverage check skipped.
✨ Finishing touches
  • 📝 Generate Docstrings
🧪 Generate unit tests
  • Create PR with unit tests
  • Post copyable unit tests in a comment

Tip

👮 Agentic pre-merge checks are now available in preview!

Pro plan users can now enable pre-merge checks in their settings to enforce checklists before merging PRs.

  • Built-in checks – Quickly apply ready-made checks to enforce title conventions, require pull request descriptions that follow templates, validate linked issues for compliance, and more.
  • Custom agentic checks – Define your own rules using CodeRabbit’s advanced agentic capabilities to enforce organization-specific policies and workflows. For example, you can instruct CodeRabbit’s agent to verify that API documentation is updated whenever API schema files are modified in a PR. Note: Upto 5 custom checks are currently allowed during the preview period. Pricing for this feature will be announced in a few weeks.

Please see the documentation for more information.

Example:

reviews:
  pre_merge_checks:
    custom_checks:
      - name: "Undocumented Breaking Changes"
        mode: "warning"
        instructions: |
          Pass/fail criteria: All breaking changes to public APIs, CLI flags, environment variables, configuration keys, database schemas, or HTTP/GraphQL endpoints must be documented in the "Breaking Change" section of the PR description and in CHANGELOG.md. Exclude purely internal or private changes (e.g., code not exported from package entry points or explicitly marked as internal).

Please share your feedback with us on this Discord post.


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

Copy link

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

Actionable comments posted: 0

🧹 Nitpick comments (1)
packages/message-parser/tests/link.test.ts (1)

45-54: Good regression test; please add a few more edge cases to prevent future regressions.

To cover delimiter handling and nesting at string ends, consider adding:

@@ test.each([
   [
     '[link](https://example.com/query?this=(is)&a=problem)',
     [
       paragraph([
         link('https://example.com/query?this=(is)&a=problem', [
           plain('link'),
         ]),
       ]),
     ],
   ],
+  [
+    '[link](https://example.com/path_(with)_parens)',
+    [paragraph([link('https://example.com/path_(with)_parens', [plain('link')])])],
+  ],
+  [
+    '[link](https://example.com/a(b(c)d)e?x=(y)z)',
+    [paragraph([link('https://example.com/a(b(c)d)e?x=(y)z', [plain('link')])])],
+  ],
+  [
+    '[link](https://example.com/endswithparen())',
+    [paragraph([link('https://example.com/endswithparen()', [plain('link')])])],
+  ],
📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 1c6ee55 and 2d6bc27.

📒 Files selected for processing (2)
  • packages/message-parser/src/grammar.pegjs (2 hunks)
  • packages/message-parser/tests/link.test.ts (1 hunks)
🧰 Additional context used
🧬 Code graph analysis (1)
packages/message-parser/tests/link.test.ts (1)
packages/message-parser/src/utils.ts (2)
  • paragraph (27-27)
  • plain (70-70)
🔇 Additional comments (2)
packages/message-parser/src/grammar.pegjs (2)

297-302: Fix is correct; ensure we don’t swallow the closing “)” delimiter in link.

Allowing “)” in URLBody solves the truncation for URLs containing parentheses. Given References expects a literal “)” after LinkRef, please verify we don’t consume the delimiter in cases where the URL ends with a “)” (e.g., https://example.com/path_(with)_parens). Existing tests suggest backtracking keeps the delimiter intact, but adding a couple of guard tests would lock this down.


285-285: OK to remove the stale TODO here.

No functional impact; LinkRef alternatives remain intact.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Markdown links with brackets in url not working
2 participants