fix: special characters in markdown links#4195
Conversation
# Conflicts: # apps/web/src/components/ChatMarkdown.browser.tsx # apps/web/src/components/ChatMarkdown.tsx
|
Important Review skippedAuto reviews are disabled on this repository. Please check the settings in the CodeRabbit UI or the ⚙️ Run configurationConfiguration used: Repository UI Review profile: CHILL Plan: Pro Run ID: You can disable this status message by setting the Use the checkbox below for a quick retry:
✨ Finishing Touches🧪 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 |
ApprovabilityVerdict: Needs human review This bug fix involves non-trivial refactoring of markdown link parsing logic - replacing regex extraction with an AST-based plugin approach and changing path normalization behavior. While well-tested and scoped to markdown rendering, the behavioral changes to link resolution warrant human review. You can customize Macroscope's approvability policy. Learn more. |
Before
After
Reopen of #2846
What Changed
Why
Filenames with square brackets or parenthesis or other special characters in them (param route files, route group folders) were unlinkable to, this pr fixes that
UI Changes
N/A
Checklist
Note
Medium Risk
Touches link classification and sanitization in chat rendering; misclassification could break external links or mis-open paths, but scope is limited to markdown link handling with expanded tests.
Overview
Fixes chat markdown file links so paths with route groups, brackets, and other punctuation resolve and open correctly instead of being treated as broken or external URLs.
markdown-links:normalizeMarkdownLinkDestinationnow unescapes markdown-escaped punctuation (while leaving Windows backslash paths untouched) instead of stripping angle brackets. Relative path detection is reworked: multi-segment paths can include()and[], encoded segments are handled, extensionless paths likescripts/releasestill qualify conservatively, and ambiguous strings such asdocs/user%20guideare no longer classified as files. Angle-bracket destination unwrapping is removed from this flow.ChatMarkdown: The regex pre-scan that built a href→meta map is replaced by a remark plugin that walks link nodes, resolves file metadata from the ASTurl, and stampsdataFileLinkParentSuffixon nodes for duplicate-basename disambiguation; the sanitize schema allows that attribute. Link rendering resolves meta at click/render time, andurlTransformpreserves raw hrefs whenresolveMarkdownFileLinkTargetrecognizes a file path.Reviewed by Cursor Bugbot for commit e9b4530. Bugbot is set up for automated code reviews on this repo. Configure here.
Note
Fix special characters in markdown file links
normalizeMarkdownLinkDestinationwith markdown punctuation unescaping, so paths containing special characters (e.g.(,),[) are handled correctly.isLikelyPathCandidatein markdown-links.ts with a segment-based approach that reduces false positives on ambiguous encoded web paths while still accepting extensionless multi-segment paths.createFileLinkDisambiguationPluginremark plugin that annotates file link AST nodes with a parent-suffix property, replacing the previous approach of computing suffixes from raw markdown text; anchor rendering then reads this via a DOM data attribute.markdownUrlTransformso file-path-looking links that are not file URIs are passed through unchanged instead of being mangled bydefaultUrlTransform.Macroscope summarized e9b4530.