pmoreno-rodriguez / grav-theme-editorial

Editorial is a GravCMS port of the Editorial theme from HTML5Up.net.
Other
13 stars 2 forks source link

Opengraph metatags not HTML-encoded #51

Open artecnico opened 5 days ago

artecnico commented 5 days ago

If you enable the "Summary" option for the blog posts and write some special characters in the post title/body (like double quotes " or > for example), then the HTML is broken and some chars are show in the upper-left corner of the page.

If you examine the source code you can see it is broken because those special chars are not correctly HTML encoded in the Open Graph metatags.

To fix this you've to add |e('html') in the metadata.html.twig just before the truncate calls:

<meta name="og:title" property="og:title" content="{{ page.title|e('html')|raw }}" />

<meta name="og:description" property="og:description" content="{{ page.summary|striptags|e('html')|truncate(150)|raw }}" />
pmoreno-rodriguez commented 4 days ago

Hi. I can't replicate your issue. I don't see the characters in the upper corner, as you indicate. However, it is true that in the opengraph tags of the source code, double quotes have an undesirable effect on said source code.

I attached a screenshot to show double quotes in the title, without observing any strange characters in the top corner. editorial_summary_error

pmoreno-rodriguez commented 4 days ago

At the end, I managed to replicate the error, just adding "> to the end of a page title. It seems that with those characters, they are displayed in the body of the page instead of in the head. This does not happen with other templates where the |e('html') filter is not applied to the title or description of the metadata. I will have to continue investigating, although adding this filter solves the problem for now.

Thanks for your contribution.