RichMedia: skip the quote fallback link when picking the card URL #8004

Merged
lambadalambda merged 3 commits from lambadalambda/pleroma:fix/card-skip-quote-link into develop 2026-11-03 19:01:50 +00:00

Quote posts from Mastodon, Misskey and InlineQuotePolicy start with RE: <url> in a .quote-inline element. HTML.extract_first_external_url_from_object/1 took that link for the link card, so the quoted post showed twice (as quote and as card) and a real link later in the post got no card.

Links inside .quote-inline and a link equal to the object's quoteUrl are now skipped. Tests for the Mastodon paragraph, the Misskey/InlineQuotePolicy span and a bare link to the quoted post.

Quote posts from Mastodon, Misskey and InlineQuotePolicy start with `RE: <url>` in a `.quote-inline` element. `HTML.extract_first_external_url_from_object/1` took that link for the link card, so the quoted post showed twice (as quote and as card) and a real link later in the post got no card. Links inside `.quote-inline` and a link equal to the object's `quoteUrl` are now skipped. Tests for the Mastodon paragraph, the Misskey/InlineQuotePolicy span and a bare link to the quoted post.
RichMedia: skip the quote fallback link when picking the card URL
Some checks failed
ci/woodpecker/pr/changelog Pipeline was successful
ci/woodpecker/pr/lint Pipeline failed
ci/woodpecker/pr/unit-testing-elixir-1.19 unknown status
ci/woodpecker/pr/unit-testing-elixir-1.15 unknown status
d13000b2b9
Mastodon, Misskey and InlineQuotePolicy put "RE: <url>" in a .quote-inline
element at the start of a quote post. Its link was taken for the link card,
which then showed the quoted post a second time.
Merge branch 'develop' into fix/card-skip-quote-link
Some checks failed
ci/woodpecker/pr/unit-testing-elixir-1.17 Pipeline is pending
ci/woodpecker/pr/unit-testing-elixir-1.19 Pipeline is pending
ci/woodpecker/pr/changelog Pipeline was successful
ci/woodpecker/pr/lint Pipeline failed
2c872cf474
test: use sigils for HTML strings in quote link tests
All checks were successful
ci/woodpecker/pr/changelog Pipeline was successful
ci/woodpecker/pr/lint Pipeline was successful
ci/woodpecker/pr/unit-testing-elixir-1.17 Pipeline was successful
ci/woodpecker/pr/unit-testing-elixir-1.19 Pipeline was successful
0667705b77
Author
Owner

/oc review

/oc review
opencode-fix-bot left a comment

No defects found. This change is narrow, well-tested, and safe to merge.

What the change does

  • lib/pleroma/html.ex: extract_first_external_url_from_object/1 now drops the .quote-inline subtree via Floki.filter_out/2 before picking the first link, and skips any bare href exactly equal to the object's quoteUrl, falling through to the next link instead of returning the quoted post's URL.
  • test/pleroma/html_test.exs: covers the three shapes named in the PR body — Mastodon <p class="quote-inline"> paragraph, Misskey/InlineQuotePolicy <span class="quote-inline"> span, and a bare RE: <a> link equal to quoteUrl.
  • changelog.d/card-skip-quote-link.fix: follows the existing <name>.fix fragment convention.

Correctness checks

  • Floki.filter_out/2 exists in the pinned floki 0.38.0 and is already used the same way in anti_link_spam_policy.ex and language_detector.ex, so no new API risk.
  • The .quote-inline wrapper is machine-generated fallback markup (see InlineQuotePolicy.build_inline_quote/2, which emits exactly the tested <span class="quote-inline"> shape; Mastodon emits the <p> shape), not user content, so filtering the whole subtree cannot hide a genuine user link in practice.
  • When quoteUrl is absent, data["quoteUrl"] is nil and no href equals it, so behavior is identical to the old take-first-link path for non-quote posts.
  • When the quote fallback is the only link, the function returns nil and Card.get_by_object/1 correctly produces no card instead of a self-referential one.

Tests run

  • mix test test/pleroma/html_test.exs — 28 tests, 0 failures (includes the 3 new quote-link tests).
  • mix test test/pleroma/web/rich_media/card_test.exs — 3 tests, 0 failures.

Verdict

No findings. Merge-readiness: 5/5 — production-ready.

opencode-agent:job=169:generation=1

### Review: quote fallback link skipped for link cards No defects found. This change is narrow, well-tested, and safe to merge. ### What the change does - `lib/pleroma/html.ex`: `extract_first_external_url_from_object/1` now drops the `.quote-inline` subtree via `Floki.filter_out/2` before picking the first link, and skips any bare `href` exactly equal to the object's `quoteUrl`, falling through to the next link instead of returning the quoted post's URL. - `test/pleroma/html_test.exs`: covers the three shapes named in the PR body — Mastodon `<p class="quote-inline">` paragraph, Misskey/`InlineQuotePolicy` `<span class="quote-inline">` span, and a bare `RE: <a>` link equal to `quoteUrl`. - `changelog.d/card-skip-quote-link.fix`: follows the existing `<name>.fix` fragment convention. ### Correctness checks - `Floki.filter_out/2` exists in the pinned `floki 0.38.0` and is already used the same way in `anti_link_spam_policy.ex` and `language_detector.ex`, so no new API risk. - The `.quote-inline` wrapper is machine-generated fallback markup (see `InlineQuotePolicy.build_inline_quote/2`, which emits exactly the tested `<span class="quote-inline">` shape; Mastodon emits the `<p>` shape), not user content, so filtering the whole subtree cannot hide a genuine user link in practice. - When `quoteUrl` is absent, `data["quoteUrl"]` is `nil` and no `href` equals it, so behavior is identical to the old take-first-link path for non-quote posts. - When the quote fallback is the only link, the function returns `nil` and `Card.get_by_object/1` correctly produces no card instead of a self-referential one. ### Tests run - `mix test test/pleroma/html_test.exs` — 28 tests, 0 failures (includes the 3 new quote-link tests). - `mix test test/pleroma/web/rich_media/card_test.exs` — 3 tests, 0 failures. ### Verdict No findings. Merge-readiness: **5/5** — production-ready. opencode-agent:job=169:generation=1
Sign in to join this conversation.
No reviewers
No milestone
No project
No assignees
2 participants
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set

Reference
pleroma/pleroma!8004
No description provided.