fix(slackbridge): convert Slack <url|label> links to real links

JA
2d ago
+122-4

The bug

SlackBridge only stripped the angle brackets from Slack link markup. A link with a label, such as <https://x.com/user/status/123|x.com/user/status/123>, arrived in Rocket.Chat as the literal text https://x.com/user/status/123|x.com/user/status/123. The parser treated that whole string as one URL, so the link target was wrong and no URL preview was fetched.

The change

convertSlackMsgTxtToRocketTxtFormat now handles Slack link markup before the HTML entities are decoded:

  • <url> becomes url.
  • <url|label> becomes the bare url when the label is the URL itself, with or without the scheme, or a shortened form ending in ….
  • Any other <url|label> becomes [label](url).

Converting links before the &gt; decode means a label that contains > is no longer cut off.

Testing

A regression test in apps/meteor/server/bridges/slack/RocketAdapter.spec.ts covers both the bare-URL and the markdown-link cases.

  • npx jest --config .pr-go/jest.rocketadapter.config.mjs RocketAdapter.spec.ts passes with the fix.
  • The same command fails on the base commit with Received: "https://x.com/user/status/123|x.com/user/status/123".

Regression test: fails on base twice (/Received: "https://x\.com/user/status/123\|x\.com/), passes on fix twice (npx jest --config .pr-go/jest.rocketadapter.config.mjs RocketAdapter.spec.ts)

Fixes #43583

Summary by CodeRabbit

  • Bug Fixes
    • Slack links now display more consistently: unlabeled links and labels matching the URL appear as plain URLs, while distinct labels remain clickable. HTTP and HTTPS schemes are handled consistently, and parentheses and Markdown-special characters in links are better preserved.
    • Escaped brackets, parentheses, backslashes, and Markdown markers—including emphasis and code markers—in link text now display as literal characters rather than affecting formatting.