Skip to content

fix(renderText): recognize uppercase URL schemes#3226

Merged
adityaalifn merged 1 commit into
masterfrom
fix/uppercase-url-scheme-linkification
Jun 25, 2026
Merged

fix(renderText): recognize uppercase URL schemes#3226
adityaalifn merged 1 commit into
masterfrom
fix/uppercase-url-scheme-linkification

Conversation

@adityaalifn

@adityaalifn adityaalifn commented Jun 25, 2026

Copy link
Copy Markdown
Contributor

Summary

URLs written with an uppercase scheme (e.g. HTTPS://example.com) were rendered incorrectly in message text:

  • The anchor was emitted without the str-chat__message-url-link class, so the link looked like plain, unstyled text (effectively "not recognized as a link").
  • The scheme was not stripped from the displayed text, so users saw HTTPS://example.com instead of example.com.

The lowercase equivalent (https://example.com) renders correctly, so the bug is purely about case sensitivity in two helpers.

Root cause

Two case-sensitive helpers in the renderText pipeline:

  1. componentRenderers/Anchor.tsx decided whether to apply the link class with href?.startsWith('http'). An HTTPS:// href fails this check, so isUrl was false and the str-chat__message-url-link class was dropped.
  2. regex.ts strips the scheme for display text via detectHttp = /(http(s?):\/\/)?(www\.)?/. Without the i flag it doesn't match HTTPS://, so the scheme stayed in the display text.

linkifyjs (which detects the URL) and react-markdown (which renders it) are both already case-insensitive, so they are not at fault — they correctly identify and preserve the uppercase-scheme URL. The display/styling layer was the only case-sensitive part.

The fix

- const isUrl = href?.startsWith('http');
+ const isUrl = href?.toLowerCase().startsWith('http');
- export const detectHttp = /(http(s?):\/\/)?(www\.)?/;
+ export const detectHttp = /(http(s?):\/\/)?(www\.)?/i;

Both changes are minimal and preserve the existing behavior for lowercase schemes.

Reproduction

Before the fix:

  • https://en.wikipedia.org/wiki/Apple -> styled link, display text en.wikipedia.org/wiki/Apple
  • HTTPS://en.wikipedia.org/wiki/Apple -> unstyled <a> (no str-chat__message-url-link), display text HTTPS://en.wikipedia.org/wiki/Apple

After the fix, the uppercase variant renders identically to the lowercase one: a styled link with the scheme stripped from the display text, while the href keeps its original casing.

Tests

Added a regression test in renderText.test.tsx asserting that "see HTTPS://en.wikipedia.org/wiki/Apple" produces an anchor with:

  • class str-chat__message-url-link
  • href="HTTPS://en.wikipedia.org/wiki/Apple" (original casing preserved)
  • link text en.wikipedia.org/wiki/Apple (scheme stripped)

The test fails on master (the input renders as plain text with no anchor) and passes with this change. The full renderText suite (61 tests) passes; no existing snapshots changed.

Summary by CodeRabbit

  • Bug Fixes
    • URLs with uppercase or mixed-case schemes are now detected and linked correctly.
    • Link rendering now treats URL schemes case-insensitively, improving consistency for pasted links.
    • Added test coverage for uppercase URL matching and link behavior.

@coderabbitai

coderabbitai Bot commented Jun 25, 2026

Copy link
Copy Markdown

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: e17b7ce8-902f-4b53-9694-8a782e7f60a7

📥 Commits

Reviewing files that changed from the base of the PR and between b9ef6cd and 6178513.

📒 Files selected for processing (3)
  • src/components/Message/renderText/__tests__/renderText.test.tsx
  • src/components/Message/renderText/componentRenderers/Anchor.tsx
  • src/components/Message/renderText/regex.ts

📝 Walkthrough

Walkthrough

renderText now linkifies URLs with uppercase schemes while preserving the original href value. The HTTP detection regex and anchor classification logic both use case-insensitive matching, and a test covers an uppercase HTTPS URL.

Changes

Uppercase HTTP URL matching

Layer / File(s) Summary
Case-insensitive detection and rendering
src/components/Message/renderText/regex.ts, src/components/Message/renderText/componentRenderers/Anchor.tsx, src/components/Message/renderText/__tests__/renderText.test.tsx
detectHttp now matches HTTP schemes case-insensitively, Anchor checks the scheme after lowercasing href, and the test verifies uppercase HTTPS link rendering and the original href.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

Poem

A rabbit hopped through linky glade,
Where HTTPS in caps was neatly made.
The carrot path was found just right,
And anchors gleamed in morning light 🥕
Thump-thump — renderText is in good shape!

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly summarizes the main change: renderText now recognizes uppercase URL schemes.
Description check ✅ Passed The description covers the goal, implementation, reproduction, and tests, but it does not include the template's UI Changes screenshots section.
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.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch fix/uppercase-url-scheme-linkification

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.

@github-actions

Copy link
Copy Markdown

Size Change: +9 B (0%)

Total Size: 797 kB

📦 View Changed
Filename Size Change
dist/cjs/index.js 259 kB +5 B (0%)
dist/es/index.mjs 256 kB +4 B (0%)
ℹ️ View Unchanged
Filename Size
dist/cjs/audioProcessing.js 1.74 kB
dist/cjs/channel-detail.js 22.9 kB
dist/cjs/emojis.js 2.56 kB
dist/cjs/mp3-encoder.js 814 B
dist/cjs/ReactPlayerWrapper.js 547 B
dist/cjs/useChannelHeaderOnlineStatus.js 37.7 kB
dist/cjs/useMessageComposerController.js 1.01 kB
dist/cjs/useNotificationApi.js 52.8 kB
dist/css/channel-detail.css 2.84 kB
dist/css/emoji-picker.css 178 B
dist/css/emoji-replacement.css 456 B
dist/css/index.css 41.2 kB
dist/es/audioProcessing.mjs 1.65 kB
dist/es/channel-detail.mjs 22.6 kB
dist/es/emojis.mjs 2.48 kB
dist/es/mp3-encoder.mjs 768 B
dist/es/ReactPlayerWrapper.mjs 485 B
dist/es/useChannelHeaderOnlineStatus.mjs 37.1 kB
dist/es/useMessageComposerController.mjs 937 B
dist/es/useNotificationApi.mjs 51.5 kB

compressed-size-action

@codecov

codecov Bot commented Jun 25, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 84.19%. Comparing base (2312d89) to head (6178513).
⚠️ Report is 1 commits behind head on master.

Additional details and impacted files
@@            Coverage Diff             @@
##           master    #3226      +/-   ##
==========================================
+ Coverage   84.18%   84.19%   +0.01%     
==========================================
  Files         485      485              
  Lines       14867    14867              
  Branches     4704     4704              
==========================================
+ Hits        12516    12518       +2     
+ Misses       2351     2349       -2     

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@oliverlaz oliverlaz left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

thanks @adityaalifn

@adityaalifn adityaalifn merged commit 21d57e3 into master Jun 25, 2026
14 checks passed
@adityaalifn adityaalifn deleted the fix/uppercase-url-scheme-linkification branch June 25, 2026 12:44
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.

2 participants