Page 1 of 1

opengraph conten plugin: wrong handling of " (" ")

Posted: 11 May 2025, 15:34
by Dirk67
if you have quotes (") in your articles title or article-text
joomla makes " out of them ... (PHP: htmlspecialchars)
so far so good ...

but then in the og: tags
there appears "
(maybe double execution of (PHP: htmlspecialchars) ? -> maybe use the $double_encode = false parameter of htmlspecialchars)

Re: opengraph conten plugin: wrong handling of " (" ")

Posted: 13 May 2025, 11:04
by Dirk67
it seems that the call
$document->setMetadata
in .../plugins/content/phocaopengraph/phocaopengraph.php
on line 111
does already a htmlspecialchars conversion on its own* (?):

Test: if I insert

Code: Select all

$document->setMetadata(htmlspecialchars($name, ENT_COMPAT, 'UTF-8'), '& < > "', $typeString);
at line 111 for test purposes,
in the html head shows correctly:

Code: Select all

<meta property="og:title" content="&amp; &lt; &gt; &quot;">
strangely enough:
*this works for the $value part only (second argument of $document->setMetadata)
but not for the name part (first argument of $document->setMetadata)

-----------

using Joomla 5.3.0 / PHP 8.4.3

Re: opengraph conten plugin: wrong handling of &quot; (" ")

Posted: 13 May 2025, 11:48
by Dirk67
I think the second/double htmlspecialchars happens (in Joomla core) here:
https://github.com/joomla/joomla-cms/bl ... r.php#L158

Code: Select all

$buffer .= $tab . '<meta ' . $type . '="' . $name . '" content="'. htmlspecialchars($contents, ENT_COMPAT, 'UTF-8') . '">' . $lnEnd;
"type" and "name" are left unchanged while "content" gets a htmlspecialchars conversion ...

Re: opengraph conten plugin: wrong handling of &quot; (" ")

Posted: 14 May 2025, 01:22
by Jan
Hi, are you sure, that "setMetadata" method uses this function?

Jan

Re: opengraph conten plugin: wrong handling of &quot; (" ")

Posted: 21 May 2025, 18:40
by Dirk67
no not sure,

but if I remove* the
the "htmlspecialchars" from the $document->setMetadata calls in
".../plugins/content/phocaopengraph/phocaopengraph.php"
everything works as expected even when inserting the characters " < > & in the title or desription

*(for the $value part only (second argument of $document->setMetadata)
but not for the $name part (first argument of $document->setMetadata))


what results came out with your own tests ?

Re: opengraph conten plugin: wrong handling of &quot; (" ")

Posted: 22 May 2025, 16:55
by Jan
I get everything OK:

Image

Image

The question is if there is no other process which can somehow influence it. :idea:

Jan