discover: support hyperlinks and newlines in protocol descriptions (port to v5.47.0) - #2989
Merged
Conversation
…2985) * discover: support hyperlinks and newlines in protocol descriptions Adds a LinkifiedText component that turns markdown-style [text](https://...) links and bare https:// URLs in a protocol's description into clickable links, restricted to https to match the existing isSafeHttpsUrl convention used for protocol.websiteUrl. Also preserves embedded newlines via white-space: pre-line, which the description text previously collapsed. * discover: fix link parsing for balanced parens, restore link underline Addresses Copilot review feedback on #2985: - parseLinkedText previously excluded all parentheses from a URL's character class, truncating URLs that legitimately contain them (e.g. Wikipedia-style https://.../Function_(mathematics)), and for the markdown form the first ")" inside the URL was mistaken for the link's closing paren. Replaced the regex-based matcher with a small scanner that tracks paren depth so balanced parens stay part of the URL, and only an unmatched ")" ends it. Added regression tests for both the bare-URL and markdown-link forms. - ProtocolDetailsPanel's global stylesheet resets all <a> underlines, so the description's links were distinguished from surrounding text by color alone. Restored text-decoration: underline on them so the link cue doesn't depend on color perception. * discover: fix nested-bracket and label-URL parsing bugs Addresses further review feedback on #2985: - Copilot: a markdown label containing its own https:// URL (e.g. [https://a.example](https://b.example)) was mishandled because the parser scanned for bare https:// occurrences first, matching the label's URL before considering the markdown link around it. - aristidesstaffieri: a stray, unmatched "[" before a real markdown link could swallow the real link into its own (invalid) label, since the backward-scanning opener regex always matched from the leftmost "[" rather than the nearest one. Replaced the backward-scanning approach with a forward scanner that looks for the next "[" or bare "https://" (whichever comes first) and only commits to a markdown link once a complete, valid [label](https://...) is found starting there; an incomplete/invalid "[" is left as literal text and scanning resumes just past it. This also incidentally required tightening the URL boundary characters to include quotes, since a bare URL inside quotes was absorbing the closing quote. Added regression tests for all three cases. * discover: reject malformed URLs, keep brackets in markdown destinations Addresses further Copilot feedback on #2985: - A candidate was only checked against the "https://" text prefix, so malformed values like bare "https://" or "https://?query" (no host) were still emitted as clickable links, even though the existing isSafeHttpsUrl guard in Discover/index.tsx would reject them. Validate every candidate with `new URL(...)` and require the "https:" protocol before treating it as a link; reject candidates are left as plain text (the original substring, not `url.href`, is still used for display/navigation, since the WHATWG URL parser normalizes some inputs like adding a trailing slash to a bare origin). - The URL boundary excluded square brackets universally, which broke markdown-link destinations containing the common `?tag[]=value` query syntax: the parse failed and the same target was then emitted as a truncated bare link pointing at the wrong address. Brackets are now only excluded from a *bare* URL's boundary (to avoid ambiguity with an immediately following markdown link) - a markdown destination's balanced closing paren is enough to bound it on its own. Added regression tests for both. --------- Co-authored-by: Claude <noreply@anthropic.com>
Contributor
|
PR Preview build is ready: https://github.com/stellar/freighter/releases/tag/untagged-45cad153afa865ce568f (SDF collaborators only — install instructions in the release description) |
Contributor
There was a problem hiding this comment.
Pull request overview
Ports hyperlink and newline support for Discover protocol descriptions to the emergency-release branch.
Changes:
- Adds safe HTTPS link parsing and rendering.
- Preserves description newlines and styles links accessibly.
- Adds parser tests and documents supported syntax.
Reviewed changes
Copilot reviewed 6 out of 6 changed files in this pull request and generated 2 comments.
Show a summary per file
| File | Description |
|---|---|
@shared/api/types/types.ts |
Documents description syntax. |
extension/src/popup/basics/LinkifiedText/index.tsx |
Renders parsed links. |
extension/src/popup/basics/LinkifiedText/parseLinkedText.ts |
Parses Markdown and bare URLs. |
extension/src/popup/basics/LinkifiedText/__tests__/parseLinkedText.test.ts |
Tests parser behavior. |
extension/src/popup/views/Discover/components/ProtocolDetailsPanel/index.tsx |
Uses linkified descriptions. |
extension/src/popup/views/Discover/components/ProtocolDetailsPanel/styles.scss |
Preserves newlines and styles links. |
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Port #2985 to the
emergency-releasebranch so we can release it on5.47.0independently of other bigger changes present onmasterbranch (e.g. balances-v2 migration).