Skip to content

fix(message-parser): avoid protocol duplication for invalid absolute URLs#39293

Closed
Shreyas2004wagh wants to merge 2 commits intoRocketChat:developfrom
Shreyas2004wagh:fix/message-parser-invalid-absolute-url-protocol-duplication
Closed

fix(message-parser): avoid protocol duplication for invalid absolute URLs#39293
Shreyas2004wagh wants to merge 2 commits intoRocketChat:developfrom
Shreyas2004wagh:fix/message-parser-invalid-absolute-url-protocol-duplication

Conversation

@Shreyas2004wagh
Copy link
Copy Markdown
Contributor

@Shreyas2004wagh Shreyas2004wagh commented Mar 3, 2026

Summary

  • Preserve absolute URL sources in autoLink even when URL() validation fails (for example, invalid ports).
  • Avoid adding a leading // to already-absolute inputs such as https://rocket.chat:99999.
  • Add parser-level and helper-level regression tests for invalid absolute port cases.

Problem

When autoLink received an absolute URL that failed URL() validation, it prepended // and produced malformed href values like //https://rocket.chat:99999.

Testing

Summary by CodeRabbit

  • New Features
    • Improved URL handling in message parsing: links with absolute schemes (http, https, custom) are now recognized and preserved as entered.
    • Message links retain original protocol and port information, preventing unintended rewrites for edge-case URLs.

@changeset-bot
Copy link
Copy Markdown

changeset-bot Bot commented Mar 3, 2026

⚠️ No Changeset found

Latest commit: 1d9e883

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

@dionisio-bot
Copy link
Copy Markdown
Contributor

dionisio-bot Bot commented Mar 3, 2026

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

@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai Bot commented Mar 3, 2026

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 101e2d9 and 1d9e883.

📒 Files selected for processing (1)
  • packages/message-parser/src/utils.ts
🚧 Files skipped from review as they are similar to previous changes (1)
  • packages/message-parser/src/utils.ts

Walkthrough

Adds an internal helper to detect absolute URL schemes and updates autoLink to treat sources with absolute schemes as already-valid hrefs; adds tests verifying autoLink preserves original protocol/port for invalid absolute URLs (e.g., out-of-range ports).

Changes

Cohort / File(s) Summary
URL Scheme Detection & Linking
packages/message-parser/src/utils.ts
Adds hasAbsoluteSchemePrefix to detect absolute URL schemes and updates autoLink so strings with absolute schemes are used as-is (no // prefixing).
URL Tests
packages/message-parser/tests/url.test.ts
Adds tests ensuring autoLink preserves the original protocol and port for invalid/out-of-range port numbers in absolute URLs (e.g., https://rocket.chat:99999).

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

Suggested labels

type: bug

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly and specifically describes the main change: fixing protocol duplication for invalid absolute URLs in the message parser.
Linked Issues check ✅ Passed The PR addresses the requirement in linked issue #39295 to handle invalid absolute URL protocol-duplication, with code changes (new helper, updated autoLink logic) and test coverage.
Out of Scope Changes check ✅ Passed All changes are directly related to fixing the invalid absolute URL protocol-duplication issue; no unrelated modifications are present.
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

@cubic-dev-ai cubic-dev-ai Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No issues found across 2 files

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.

Actionable comments posted: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In `@packages/message-parser/src/utils.ts`:
- Line 78: The scheme regex in hasAbsoluteSchemePrefix currently allows a
leading digit and omits the dot character; update the regex used in
hasAbsoluteSchemePrefix to enforce RFC 3986: require the first character to be a
letter and allow letters, digits, plus, dot and hyphen for the remaining
characters (respecting the existing max-length logic), so it correctly detects
schemes like "com.example://". Replace the current pattern in
hasAbsoluteSchemePrefix with one that matches a leading letter followed by
allowed scheme chars and "://".

ℹ️ Review info

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between b7ff7b2 and 101e2d9.

📒 Files selected for processing (2)
  • packages/message-parser/src/utils.ts
  • packages/message-parser/tests/url.test.ts
📜 Review details
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (1)
  • GitHub Check: cubic · AI code reviewer
🧰 Additional context used
📓 Path-based instructions (1)
**/*.{ts,tsx,js}

📄 CodeRabbit inference engine (.cursor/rules/playwright.mdc)

**/*.{ts,tsx,js}: Write concise, technical TypeScript/JavaScript with accurate typing in Playwright tests
Avoid code comments in the implementation

Files:

  • packages/message-parser/tests/url.test.ts
  • packages/message-parser/src/utils.ts
🧠 Learnings (6)
📓 Common learnings
Learnt from: ggazzo
Repo: RocketChat/Rocket.Chat PR: 35995
File: apps/meteor/app/api/server/v1/rooms.ts:1107-1112
Timestamp: 2026-02-23T17:53:18.785Z
Learning: In Rocket.Chat PR reviews, maintain strict scope boundaries—when a PR is focused on a specific endpoint (e.g., rooms.favorite), avoid reviewing or suggesting changes to other endpoints that were incidentally refactored (e.g., rooms.invite) unless explicitly requested by maintainers.
📚 Learning: 2025-12-10T21:00:54.909Z
Learnt from: KevLehman
Repo: RocketChat/Rocket.Chat PR: 37091
File: ee/packages/abac/jest.config.ts:4-7
Timestamp: 2025-12-10T21:00:54.909Z
Learning: Rocket.Chat monorepo: Jest testMatch pattern '<rootDir>/src/**/*.spec.(ts|js|mjs)' is valid in this repo and used across multiple packages (e.g., packages/tools, ee/packages/omnichannel-services). Do not flag it as invalid in future reviews.

Applied to files:

  • packages/message-parser/tests/url.test.ts
📚 Learning: 2025-11-24T17:08:17.065Z
Learnt from: CR
Repo: RocketChat/Rocket.Chat PR: 0
File: .cursor/rules/playwright.mdc:0-0
Timestamp: 2025-11-24T17:08:17.065Z
Learning: Applies to apps/meteor/tests/e2e/**/*.spec.ts : Ensure tests run reliably in parallel without shared state conflicts

Applied to files:

  • packages/message-parser/tests/url.test.ts
📚 Learning: 2026-02-24T19:36:55.089Z
Learnt from: juliajforesti
Repo: RocketChat/Rocket.Chat PR: 38493
File: apps/meteor/tests/e2e/page-objects/fragments/home-content.ts:60-82
Timestamp: 2026-02-24T19:36:55.089Z
Learning: In RocketChat/Rocket.Chat e2e tests (apps/meteor/tests/e2e/page-objects/fragments/home-content.ts), thread message preview listitems do not have aria-roledescription="message", so lastThreadMessagePreview locator cannot be scoped to messageListItems (which filters for aria-roledescription="message"). It should remain scoped to page.getByRole('listitem') or mainMessageList.getByRole('listitem').

Applied to files:

  • packages/message-parser/tests/url.test.ts
📚 Learning: 2026-02-26T19:25:44.063Z
Learnt from: gabriellsh
Repo: RocketChat/Rocket.Chat PR: 38778
File: packages/ui-voip/src/providers/useMediaSession.ts:192-192
Timestamp: 2026-02-26T19:25:44.063Z
Learning: In the Rocket.Chat repository, do not reference Biome lint rules in code review feedback. Biome is not used even if biome.json exists; only reference Biome rules if there is explicit, project-wide usage documented. For TypeScript files, review lint implications without Biome guidance unless the project enables Biome rules.

Applied to files:

  • packages/message-parser/tests/url.test.ts
  • packages/message-parser/src/utils.ts
📚 Learning: 2026-02-26T19:25:44.063Z
Learnt from: gabriellsh
Repo: RocketChat/Rocket.Chat PR: 38778
File: packages/ui-voip/src/providers/useMediaSession.ts:192-192
Timestamp: 2026-02-26T19:25:44.063Z
Learning: In this repository (RocketChat/Rocket.Chat), Biome lint rules are not used even if a biome.json exists. When reviewing TypeScript files (e.g., packages/ui-voip/src/providers/useMediaSession.ts), ensure lint suggestions do not reference Biome-specific rules. Rely on general ESLint/TypeScript lint rules and project conventions instead.

Applied to files:

  • packages/message-parser/tests/url.test.ts
  • packages/message-parser/src/utils.ts
🧬 Code graph analysis (1)
packages/message-parser/tests/url.test.ts (2)
packages/message-parser/src/utils.ts (3)
  • paragraph (27-27)
  • link (80-83)
  • autoLink (85-100)
packages/message-parser/tests/helpers.ts (2)
  • paragraph (6-6)
  • link (39-42)
🔇 Additional comments (3)
packages/message-parser/src/utils.ts (1)

97-97: Good fallback ordering for invalid absolute URLs

Line 97 correctly preserves already-absolute sources before applying //, which addresses the reported duplicated-protocol regression path.

packages/message-parser/tests/url.test.ts (2)

28-29: Regression cases are well-targeted

These added parser cases cover the invalid-absolute-port scenarios that triggered protocol duplication and validate both root and path variants.


162-165: Helper-level regression coverage looks solid

The helper test explicitly guards invalid absolute port handling (including boundary-adjacent 65536), which strengthens future refactor safety.

Comment thread packages/message-parser/src/utils.ts Outdated
@ggazzo
Copy link
Copy Markdown
Member

ggazzo commented Apr 17, 2026

Hey @Shreyas2004wagh, thank you for your contribution! 🙏

Your changes have been consolidated into #39853, where we merged all message-parser PRs together to make it easier to test and validate everything as a single unit.

That PR has already been merged into develop, so your work is included. Closing this one — thanks again!

@ggazzo ggazzo closed this Apr 17, 2026
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.

chore(message-parser): tracking issue for parser correctness, performance, and test hardening

2 participants