HTML entity codes in the body are getting encoded twice.   turns into  .

<meta property="og:description" content="&amp;amp;nbsp;This is what I heard them say:&amp;amp;ldquo;You can have the others, but Tinashe comes with me.&amp;amp;rdquo;&amp;amp;ldquo;Why would you separate the kids? Especially Tinashe, who needs his brothers and sisters arou..." />

Facebook renders &amp;amp;nbsp; as &nbsp;. I believe the module should be outputting &amp;nbsp;.

This seems to happen regardless of what text format is used. Tested with both 7.x-1.2 and latest dev release.

See here for an example: http://trope.com/imow/stories/broken-toys

Thanks!

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

eusonic’s picture

Issue summary: View changes

Added code tags for clarity.

Raphael Apard’s picture

Same problème for me.

It's works if I replace line 273 of opengraph_meta.common.inc :
$v = htmlspecialchars(htmlspecialchars_decode($v));
by :
$v = html_entity_decode($v, ENT_COMPAT, 'UTF-8');

Only " will be encoded, but i can't get correct a full encoded value.

eusonic’s picture

I fixed this by changing line 273 in opengraph_meta.common.inc

from:
$v = htmlspecialchars(htmlspecialchars_decode($v));

to:
$v = htmlspecialchars_decode($v);

Is there any reason why this will backfire on me?

k4v’s picture

I can confirm this bug, is #2 a valid fix?

k4v’s picture

zerolab’s picture

the fix from #1 worked for me. Plus it fixed a problem with the Facebook sharer which extracts titles from the og:title tag. Don't would turn into D&#039;t (notice the apostrophe)

Cameron Tod’s picture

Status: Active » Needs review
FileSize
64 bytes

I can confirm the fix in #2 works locally too. I am about to push it to a live site so will report if there are any other issues.

I've rolled this up into a patch - eusonic I attributed the commit to you.

Cameron Tod’s picture

Ugh bad patch, sorry.

q2_faith’s picture

the fix from #1 worked for me. But replace

ENT_COMPAT

on

ENT_QUOTES
jim005’s picture

Status: Needs review » Patch (to be ported)

#7 works well for French content. Thanks !

louisjimenez’s picture

Is there a fix for 6.x-1.7 ? I am also having this issue at http://drupal.org/node/1826258#comment-7000638 . Thanks!

louisjimenez’s picture

Issue summary: View changes

Edited to be a little clearer.

chrisarusso’s picture

Yes to number q2_faith: per PHP's documentation here: http://us2.php.net/manual/en/function.html-entity-decode.php

Constant Name	Description
ENT_COMPAT	Will convert double-quotes and leave single-quotes alone.
ENT_QUOTES	Will convert both double and single quotes.
ENT_NOQUOTES	Will leave both double and single quotes unconverted.
ENT_HTML401	 Handle code as HTML 4.01.
ENT_XML1	 Handle code as XML 1.
ENT_XHTML	 Handle code as XHTML.
ENT_HTML5	 Handle code as HTML 5.

We clearly need ENT_QUOTES to handle both double and single quotes.

Module seems unattended. I'll patch if requested

wonder95’s picture

Issue summary: View changes

I ran into this same problem, and here's how we modified line 273 to get it to work.

$v = html_entity_decode(htmlspecialchars_decode(htmlspecialchars($v)), ENT_QUOTES);
Demian’s picture

I had an og:title with an apostrophe and og:description with double quotation marks.

In my case, every solution above, was decoding either the apostrophe or the quotation marks, not both.

The modified line bellow was the solution

$v = htmlspecialchars(html_entity_decode($v, ENT_QUOTES, 'UTF-8'), ENT_QUOTES, 'UTF-8');

rick_p’s picture

I was experiencing HTML entities being displayed as text, showing up when content was shared via ShareThis or similar widgets, particularly with facebook’s sharer. However, this issue has manifested itself in other ways as noted above.

As illmasterc mentions above, ENT_QUOTES will convert both double and single quotes, so I have rolled the work Demian did (directly above) into a patch. I credited both.

BTMash’s picture

Status: Patch (to be ported) » Needs work

@rick_p pointed me to this issue. I'm not sure why the issue status is on 'Patch - To be ported' as it was never committed to the repository. I'm setting it to 'needs work' based on the patch that @rick_p wrote (the patch works, it should just get cleaned up). See below.

  1. +++ b/opengraph_meta.common.inc
    @@ -254,7 +254,7 @@ class OpenGraphMeta {
    -
    

    Clean up the spacing here. This can be reverted back.

  2. +++ b/opengraph_meta.common.inc
    @@ -266,7 +266,10 @@ class OpenGraphMeta {
    -            $v = htmlspecialchars(htmlspecialchars_decode($v));
    +// this was not working to prevent html entities from rendering as text.
    +//            $v = htmlspecialchars(htmlspecialchars_decode($v));
    +// this works
    +		    $v = htmlspecialchars(html_entity_decode($v, ENT_QUOTES, 'UTF-8'), ENT_QUOTES, 'UTF-8');
    

    Remove the commented lines. And fix up spacing .

rick_p’s picture

Cleaned up code as requested: Fixed spacing, removed comments, removed deprecated code.

rick_p’s picture

Missed a couple of tabbed spaces.

BTMash’s picture

Status: Needs work » Reviewed & tested by the community

Updated code looks great.