fix: enhance link title parsing with hyphens and underscores in URL's
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.comhttps://developer.rocket.chat?query=query_with_underscorehttps://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
- Parse a markdown link with a query string containing an underscore:
[testwithatextcontainingan_here](http://example.com?a_param)
- 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)
- Parse a plain autolink URL containing underscores:
https://developer.rocket.chat/path_with_underscorehttps://developer.rocket.chat?query=query_with_underscore
- 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.