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

grimal’s picture

Issue summary: View changes

escaped html entity

DamienMcKenna’s picture

Version: 7.x-1.0-beta7 » 7.x-1.x-dev
Component: Code » Views integration
mikemccaffrey’s picture

Title: Metatag Views "'" in place of apostrophe in meta title tag » Metatag "'" in place of apostrophe in meta title tag
Component: Views integration » Code

This 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.

KarlShea’s picture

This 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.

DamienMcKenna’s picture

Status: Active » Closed (works as designed)

I'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.