Support for Drupal 7 is ending on 5 January 2025—it’s time to migrate to Drupal 10! Learn about the many benefits of Drupal 10 and find migration tools in our resource center.
I've a view that is filtering nodes based on a taxonomy term and the title is overridden by the context argument "%1".
When a taxonomy term has a quote it's displayed as '
Disabling the module "Metatag: Views" all works good.
Debugging in the deep the issue i've discover that the problem is the sanitization applied by the DrupalTextMetaTag->getValue() function extended by DrupalTitleMetaTag.
So DrupalTitleMetaTag needs to redefine the getValue() function, in my solution i've set the sanitize option to false and used filter_xss() instead:
class DrupalTitleMetaTag extends DrupalTextMetaTag {
public function getValue(array $options = array()) {
$name = "metatag:" . $options["instance"] . ":" . $this->info["name"];
$options += array(
'token data' => array(),
'clear' => TRUE,
'sanitize' => FALSE,
'raw' => FALSE,
);
$value = metatag_translate($name, $this->data['value']);
if (empty($options['raw'])) {
// Give other modules the opportunity to use hook_metatag_pattern_alter()
// to modify defined token patterns and values before replacement.
drupal_alter('metatag_pattern', $value, $options['token data']);
$value = filter_xss(token_replace($value, $options['token data'], $options));
}
$value = strip_tags(decode_entities($value));
$value = trim($value);
return $value;
}
}
Comments
Comment #0.0
grimal CreditAttribution: grimal commentedescaped html entity
Comment #1
DamienMcKennaComment #2
mikemccaffreyThis does not exclusively seem like an issue with metatag views, unless that module is really reaching into things that it should not.
While editing a node, if I put a title with an apostrophe like "This page's title" into the "Content title" field in the "Open Graph" section of the "Meta tags" vertical tab, it shows up escaped in the meta property="og:title" tag.
My site is running 7.x-1.4, but I will test again with 7.x-1.x-dev or 7.x-1.5-beta1 later to see if this has been addressed already in another ticket.
Comment #3
KarlSheaThis is definitely an issue with Metatag in general, I'm running into this without Metatag Views enabled. og:title includes ' and Facebook isn't converting it to an apostrophe.Turns out Facebook was caching it; I forced a crawl in the Facebook debug tool and it looks right.
Comment #4
DamienMcKennaI'm closing this. It is completely OK for the HTML to have escaped characters, it's up to the web browser / scraper to convert the characters as needed.