fix(renderText): recognize uppercase URL schemes#3226
Conversation
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: defaults Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (3)
📝 WalkthroughWalkthroughrenderText now linkifies URLs with uppercase schemes while preserving the original ChangesUppercase HTTP URL matching
Estimated code review effort🎯 2 (Simple) | ⏱️ ~10 minutes Poem
🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
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. Comment |
|
Size Change: +9 B (0%) Total Size: 797 kB 📦 View Changed
ℹ️ View Unchanged
|
Codecov Report✅ All modified and coverable lines are covered by tests. 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. 🚀 New features to boost your workflow:
|
Summary
URLs written with an uppercase scheme (e.g.
HTTPS://example.com) were rendered incorrectly in message text:str-chat__message-url-linkclass, so the link looked like plain, unstyled text (effectively "not recognized as a link").HTTPS://example.cominstead ofexample.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
renderTextpipeline:componentRenderers/Anchor.tsxdecided whether to apply the link class withhref?.startsWith('http'). AnHTTPS://href fails this check, soisUrlwasfalseand thestr-chat__message-url-linkclass was dropped.regex.tsstrips the scheme for display text viadetectHttp = /(http(s?):\/\/)?(www\.)?/. Without theiflag it doesn't matchHTTPS://, so the scheme stayed in the display text.linkifyjs(which detects the URL) andreact-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
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 texten.wikipedia.org/wiki/AppleHTTPS://en.wikipedia.org/wiki/Apple-> unstyled<a>(nostr-chat__message-url-link), display textHTTPS://en.wikipedia.org/wiki/AppleAfter the fix, the uppercase variant renders identically to the lowercase one: a styled link with the scheme stripped from the display text, while the
hrefkeeps its original casing.Tests
Added a regression test in
renderText.test.tsxasserting that"see HTTPS://en.wikipedia.org/wiki/Apple"produces an anchor with:str-chat__message-url-linkhref="HTTPS://en.wikipedia.org/wiki/Apple"(original casing preserved)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 fullrenderTextsuite (61 tests) passes; no existing snapshots changed.Summary by CodeRabbit