Commit 7dba114d authored by Francesco Placella's avatar Francesco Placella Committed by Damien McKenna
Browse files

Issue #2761909 by roshkovanv, andrewsuth, greenSkin, plach, Boobaa,...

Issue #2761909 by roshkovanv, andrewsuth, greenSkin, plach, Boobaa, DamienMcKenna, lmeurs, seancasey: og:image does not parse url from image field properly when there is a comma in the alt field.
parent 2dec4341
Loading
Loading
Loading
Loading
+3 −0
Original line number Diff line number Diff line
@@ -60,6 +60,9 @@ Metatag 8.x-1.x-dev, xxxx-xx-xx
  output.
#3254423 by andregp, DamienMcKenna: Replace deprecated APIs in tests.
#3254597 by DamienMcKenna: Remove Console integration.
#2761909 by roshkovanv, andrewsuth, greenSkin, plach, Boobaa, DamienMcKenna,
  lmeurs, seancasey: og:image does not parse url from image field properly when
  there is a comma in the alt field.


Metatag 8.x-1.16, 2021-03-15
+9 −1
Original line number Diff line number Diff line
@@ -419,14 +419,22 @@ abstract class MetaNameBase extends PluginBase {

    // If image tag src is relative (starts with /), convert to an absolute
    // link; ignore protocol-relative URLs.
    $image_tag = FALSE;
    if (strpos($value, '<img src="/') !== FALSE && strpos($value, '<img src="//') === FALSE) {
      $value = str_replace('<img src="/', '<img src="' . $base_root . '/', $value);
      $image_tag = TRUE;
    }

    if ($this->multiple()) {
      // Split the string into an array, remove empty items.
      if ($image_tag) {
        preg_match_all('%\s*(|,\s*)(<\s*img\s+[^>]+>)%m', $value, $matches);
        $values = array_filter($matches[2] ?? []);
      }
      else {
        $values = array_filter(explode(',', $value));
      }
    }
    else {
      $values = [$value];
    }