Fix truncated URLs in web search results opening broken links#388
Fix truncated URLs in web search results opening broken links#388AnthonyRonning merged 1 commit intomasterfrom
Conversation
|
Note Other AI code review bot(s) detectedCodeRabbit has detected other AI code review bot(s) in this pull request and will avoid duplicating their findings in the review comments. This may lead to a less comprehensive review. 📝 WalkthroughWalkthroughReplaces ad-hoc 150-character truncation in UnifiedChat tool output previews with a new helper Changes
Sequence Diagram(s)(omitted) Estimated code review effort🎯 2 (Simple) | ⏱️ ~8 minutes Poem
🚥 Pre-merge checks | ✅ 4✅ Passed checks (4 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing touches
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 |
Greptile SummaryFixed truncated URLs in collapsed web search results by implementing smart truncation that preserves full URLs while showing shortened display text. The solution creates markdown links
The implementation correctly solves the reported issue where clicking truncated URLs opened broken links. Confidence Score: 4/5
Important Files Changed
Sequence DiagramsequenceDiagram
participant UC as UnifiedChat
participant TR as ToolCallRenderer
participant TM as truncateMarkdownPreservingLinks
participant MD as Markdown Component
UC->>TR: Render tool output
TR->>TR: Get output string
alt output length > 150
TR->>TM: truncateMarkdownPreservingLinks(output, 150)
TM->>TM: Check if text.length <= maxLength
TM->>TM: Find all markdown link ranges
TM->>TM: Find all plain URLs (excluding those in markdown)
alt Truncation falls inside plain URL
TM->>TM: Convert to [truncated...](fullURL)
TM-->>TR: Return markdown link
else Truncation falls inside markdown link
TM->>TM: Truncate before markdown link
TM-->>TR: Return truncated text + "..."
else Safe to truncate
TM->>TM: Truncate at maxLength
TM-->>TR: Return text + "..."
end
else output length <= 150
TR->>TR: Use full output as preview
end
TR->>MD: Render preview (with preserved URLs)
MD-->>UC: Display clickable links
|
Deploying maple with
|
| Latest commit: |
14bfe51
|
| Status: | ✅ Deploy successful! |
| Preview URL: | https://4a840e53.maple-ca8.pages.dev |
| Branch Preview URL: | https://linkfix.maple-ca8.pages.dev |
Greptile's behavior is changing!From now on, if a review finishes with no comments, we will not post an additional "statistics" comment to confirm that our review found nothing to comment on. However, you can confirm that we reviewed your changes in the status check section. This feature can be toggled off in your Code Review Settings by deselecting "Create a status check for each PR". |
|
|
||
| // Helper function to truncate text while preserving clickable links | ||
| // Converts plain URLs that would be truncated into markdown links with full href but truncated display | ||
| function truncateMarkdownPreservingLinks(text: string, maxLength: number): string { |
There was a problem hiding this comment.
I think these should move to a utility file
There was a problem hiding this comment.
Addressed code review feedback: moved truncateMarkdownPreservingLinks function from UnifiedChat.tsx to a dedicated utility file at frontend/src/utils/markdown.ts.
There was a problem hiding this comment.
Great, thanks. Please rebase into a single commit since this is a tiny change and only needs to be one commit.
There was a problem hiding this comment.
Done. Commits squashed into one. Tested the fix.
There was a problem hiding this comment.
Actionable comments posted: 1
🤖 Fix all issues with AI agents
In `@frontend/src/utils/markdown.ts`:
- Around line 10-43: Precompute all markdown link ranges by iterating
mdLinkRegex (/\[([^\]]*)\]\(([^)]+)\)/g) first and collect their start/end
indices, then when scanning plain URLs with urlRegex use those ranges to skip
any URL match whose index falls inside an existing markdown link (instead of
current brittle isInMarkdownLink heuristic); also reuse the same markdown link
ranges when checking truncation (so when maxLength falls inside a markdown link
range you truncate before the whole link as you do now), and ensure the urls
array only contains plain-URL matches that are not inside any md link range.
When web search results are collapsed, URLs were being truncated for display but the truncated text was also used as the href. Now URLs that would be cut by truncation are converted to markdown links that preserve the full URL in the href while showing truncated display text. Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
When web search results are collapsed, URLs were being truncated for display but the truncated text was also used as the href. Now URLs that would be cut by truncation are converted to markdown links that preserve the full URL in the href while showing truncated display text.
Fixes #387
Summary by CodeRabbit
Bug Fixes
Notes
✏️ Tip: You can customize this high-level summary in your review settings.