Open Graph Content Plugin - ampersand encoding problem

Phoca plugins - support for all Phoca plugins except Phoca Gallery plugins
pixelhexe
Phoca Newbie
Phoca Newbie
Posts: 5
Joined: 07 Mar 2012, 13:49

Open Graph Content Plugin - ampersand encoding problem

Post by pixelhexe »

Hello Jan,

I found a small encoding issue in Phoca Open Graph Content Plugin 6.0.2 on Joomla 5.4.7.

My Joomla configuration contains a website name with an "&", let's say:

`A & B`

Joomla itself outputs this correctly in the page title:

`<title>A &amp; B</title>`

However, Phoca Open Graph generates:

`<meta property="og:site_name" content="A &amp;amp; B">`

So the ampersand is encoded twice.

I traced this to `renderTag()` in `plugins/content/phocaopengraph/phocaopengraph.php`.

The relevant code is:

Code: Select all

<?php
$value = strip_tags(html_entity_decode($value));

...

$document->setMetadata(
    htmlspecialchars($name, ENT_COMPAT, 'UTF-8'),
    htmlspecialchars($value, ENT_COMPAT, 'UTF-8'),
    $typeString
);
?> 
If I change the second part to:

Code: Select all

<?php
$document->setMetadata(
    htmlspecialchars($name, ENT_COMPAT, 'UTF-8'),
    $value,
    $typeString
);
?> 
the output becomes correct:

`<meta property="og:site_name" content="A &amp; B">`

So it seems that `$value` should not be passed through `htmlspecialchars()` before `setMetadata()`, because Joomla encodes the value when generating the meta tag.

The `addCustomTag()` branch still needs its own `htmlspecialchars()`, since it builds the HTML string directly.

I tested this on Joomla 5.4.7 with Phoca Open Graph Content Plugin 6.0.2.

Maybe this could be fixed in a future version.

Thank you very much for all your efforts!!!