Skip to content

Q_Response::setMeta(): clear stale og:image companion tags when a later image can't be sized - #39

Open
zattak1 wants to merge 1 commit into
Qbix:mainfrom
zattak1:upstream/fix-og-image-companions
Open

Q_Response::setMeta(): clear stale og:image companion tags when a later image can't be sized#39
zattak1 wants to merge 1 commit into
Qbix:mainfrom
zattak1:upstream/fix-og-image-companions

Conversation

@zattak1

@zattak1 zattak1 commented Aug 27, 2026

Copy link
Copy Markdown
Contributor

A page that sets og:image twice can end up advertising companion tags that describe the image that lost.

Cause

setMeta() derives four companions whenever an og:image is set and getimagesize() succeeds:

if (is_array($size) && !empty($size[0]) && !empty($size[1])) {
    self::setMeta(array(
        array(... "og:image:width",      $size[0]),
        array(... "og:image:height",     $size[1]),
        array(... "og:image:secure_url", $params["content"]),
        array(... "og:image:type",       $size["mime"])
    ));
}

og:image itself is stored as self::$metas[$key] keyed by name:value, so a second call replaces the first. The four companions are only ever written, never cleared — and only written when the size lookup succeeds.

So when a page sets a sizeable og:image first (an app default on local disk) and an unsizeable one second (a stream icon that is missing, or a remote URL), the survivors are the first image's:

<meta property="og:image:width"      content="400">
<meta property="og:image:height"     content="400">
<meta property="og:image:secure_url" content="https://example.com/img/icon/400.png">
<meta property="og:image:type"       content="image/png">
<meta property="og:image"            content="https://example.com/.../icon/1787355937/1000x.jpg">

og:image:secure_url names a different image from og:image, and the declared 400×400 / image/png describes neither. Unfurlers that prefer secure_url show the wrong image entirely; the rest advertise wrong dimensions.

Fix

og:image is well-formed on its own, so clear the stale set rather than leave it describing another image. Adds Q_Response::clearMeta(), which removes metas by key from both the global set and every slot.

Verified against a live install: with a correctly sized image the companions are rewritten as before (1000/1000/image/jpeg, secure_url == og:image); with an unsizeable one they are now absent rather than stale.

…e sized

setMeta() keys metas by "name:value", so a second og:image REPLACES the
first. The four companion tags it derives -- og:image:width, :height,
:secure_url, :type -- were only ever written, never cleared, and only
written when getimagesize() succeeded.

So a page that set a sizeable og:image first (the app default, on local
disk) and an unsizeable one second (a stream icon that is missing, or
remote) ended up advertising a set that described the image that LOST:
og:image:secure_url pointed at the default while og:image pointed at the
icon, and the declared width/height/type matched neither. Unfurlers that
prefer secure_url therefore showed a different image from the one og:image
names -- which is how conversation permalinks came to show the app logo
rather than nothing at all while their og:image 404ed (ro#388).

og:image is well-formed on its own, so clear the stale set rather than
leave it describing another image. Adds Q_Response::clearMeta() to remove
metas by key from both the global set and every slot.

Refs ro#388
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