Encoding for html in Open Graph Facebook attributes

1.9k views Asked by At

I have product titles such as

Cheap Samsung 22" Television

which I need to include in an og:title tag as such:

<meta property="og:title" content="Cheap Samsung 22&amp;quot; Television"/>

However when Facebook tries to render it within a rich snippet, it doesn't render the quotation and displays it as is:

Cheap Samsung 22&quot; Television

I don't understand why it doesn't render it properly so it reads as intended? If I don't encode my string and just place it in there like this:

<meta property="og:title" content="Cheap Samsung 22" Television"/>

Then Facebook thinks the quote at the end of the 22 which means inches is the end of the content attribute and hence the string gets chopped off like this:

Cheap Samsung 22"

How do I tackle this? I am using ColdFusion's EncodeForHTMLAttribute(mystring) function to accomplish the HTML encoding on the content attribute.

UPDATE: The string was being double-encoded by ColdFusion. First on the way in to the database, and then once again when outputting on the page. I used Canonicalize after performing an Anti-Samy on the way in so the string didn't contain any encoding in the DB table. Problem solved.

0

There are 0 answers