Skip to content

fix(ui): shorten Freenet URLs in reply previews - #611

Open
skandragon wants to merge 1 commit into
freenet:mainfrom
skandragon:fix/reply-preview-freenet-label
Open

fix(ui): shorten Freenet URLs in reply previews#611
skandragon wants to merge 1 commit into
freenet:mainfrom
skandragon:fix/reply-preview-freenet-label

Conversation

@skandragon

Copy link
Copy Markdown
Contributor

Replies quoted the sender's raw gateway URL (http://127.0.0.1:7509/v1/contract/web/<id>/...) where the message body already renders the short freenet:<id-prefix> label.

The body path goes through finalize_anchors; the reply-quote strip is plain text and goes through strip_markdowncollect_mdast_text, which had no Node::Link arm. Adding one there covers all three preview call sites at once — the rendered reply strip (:381) and the two composer previews (:5313, :5384).

Label-only: the strip has no href, so there is nothing to host-rewrite there. [label](url) text is left alone, mirroring the body's "visible text equals href" rule.

Not parity with the body, deliberately

finalize_anchors compares scraped HTML anchor text against the href after markdown's sanitize_uri percent-encoding; this arm compares raw mdast on both sides. A URL whose suffix markdown percent-encodes (non-ASCII, ^, |) therefore shortens in the preview but not in the body. One-way superset, and harmless — the preview is a non-clickable text node, so the worst case is a shortened label where the body kept the full URL, never the reverse. Documented at the arm.

Tests

clean_reply_preview_shortens_bare_freenet_urls covers: bare URL with path suffix, non-loopback host, trailing-slash normalisation, non-Freenet link passthrough, explicit [label](url), and a spoof URL that only mentions the marker in its query. Mutation-checked — removing the arm reddens two assertions, inverting the guard reddens three.

cargo test -p river-ui --bins: 892 passed.

Known gaps, all pre-existing and left alone

  • Block boundaries run together (- <url>\n- xfreenet:UDzGbcWrx). The raw URL ran into the next item too; the label just makes it misleading rather than ugly. Fix belongs in the Paragraph/ListItem path.
  • Node::Image alt text is dropped entirely.

No contract/delegate/common changes — no migration or redeploy needed.

The reply-quote strip renders plain text via strip_markdown, which showed
the sender's raw gateway URL where the message body already renders a
freenet:<id-prefix> label.
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.

1 participant