Skip to content

fix: enhance link title parsing with hyphens and underscores in URL's - #41739

Open
Vaishali021103 wants to merge 1 commit into
RocketChat:developfrom
Vaishali021103:underscoresFix
Open

fix: enhance link title parsing with hyphens and underscores in URL's#41739
Vaishali021103 wants to merge 1 commit into
RocketChat:developfrom
Vaishali021103:underscoresFix

Conversation

@Vaishali021103

@Vaishali021103 Vaishali021103 commented Aug 10, 2026

Copy link
Copy Markdown

Proposed changes (including videos or screenshots)

This PR fixes URL and markdown-link parsing for cases where the URL or query string contains underscores and hyphenated values, without breaking valid host parsing or treating underscores as invalid emphasis boundaries.

The fix updates the parser rules in the message-parser grammar to allow valid URL paths and query parameters containing underscores while still rejecting malformed underscore-prefixed domains. It also adds regression coverage for real-world link cases such as:

  • [testwithatextcontainingan_here](http://example.com?a_param)
  • [test-with-a-text-containing-an_here](http://example.com?param=my_value)
  • http://te_st.com
  • https://developer.rocket.chat?query=query_with_underscore
  • https://developer.rocket.chat/path_with_underscore

This ensures markdown links remain parsed correctly in messages containing mixed hyphen/underscore URL content.

Issue(s)

Fixes #41725 URL parsing bug for markdown links and autolinks containing underscores in the path/query string and mixed hyphen/underscore link titles.

Steps to test or reproduce

  1. Parse a markdown link with a query string containing an underscore:
    • [testwithatextcontainingan_here](http://example.com?a_param)
  2. Parse a markdown link with a path/query parameter using mixed hyphen/underscore values:
    • [test-with-a-text-containing-an_here](http://example.com?param=my_value)
  3. Parse a plain autolink URL containing underscores:
    • https://developer.rocket.chat/path_with_underscore
    • https://developer.rocket.chat?query=query_with_underscore
  4. Confirm the parser still handles valid links and does not incorrectly parse malformed underscore-prefixed domains.

Further comments

This is a targeted parser fix in the message parser grammar and is covered by regression tests in the package’s link and URL test suites. The change is intentionally narrow: it preserves existing parsing behavior for valid URLs while avoiding false positives caused by underscores in host/path contexts.

Review in cubic

@dionisio-bot

dionisio-bot Bot commented Aug 10, 2026

Copy link
Copy Markdown
Contributor

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

@changeset-bot

changeset-bot Bot commented Aug 10, 2026

Copy link
Copy Markdown

⚠️ No Changeset found

Latest commit: 7302b6a

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

CLAassistant commented Aug 10, 2026

Copy link
Copy Markdown

CLA assistant check
All committers have signed the CLA.

@coderabbitai

coderabbitai Bot commented Aug 10, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

Walkthrough

The parser now uses link-title-specific emphasis rules that preserve ]( terminators. Tests cover link titles and URLs containing hyphens and underscores.

Changes

Link Title Parsing

Layer / File(s) Summary
Link-title emphasis rules and validation
packages/message-parser/src/grammar.pegjs, packages/message-parser/tests/link.test.ts
The grammar adds guarded italic and plain-run rules that exclude ] from link-title content. Tests cover hyphenated text, underscored text, and URLs with underscore-containing query parameters.

Estimated code review effort: 3 (Moderate) | ~20 minutes

Suggested labels: type: bug

Suggested reviewers: ggazzo, ricardogarim

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly describes the main change: improved Markdown link-title parsing for hyphens and underscores in URLs.

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.

@cubic-dev-ai cubic-dev-ai 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.

All reported issues were addressed across 2 files

Reply with feedback, questions, or to request a fix.

Re-trigger cubic

Comment thread packages/message-parser/src/grammar.pegjs
Comment thread packages/message-parser/src/grammar.pegjs
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.

Wrong display of hyperlinks when an underscore is present in the text

2 participants