Skip to content

Commit

Permalink
Cast metadata to string
Browse files Browse the repository at this point in the history
  • Loading branch information
pierredup authored and OskarStark committed Feb 13, 2019
1 parent 4ccd5b6 commit b73bf69
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 3 deletions.
2 changes: 1 addition & 1 deletion src/Twig/Extension/SeoExtension.php
Expand Up @@ -262,6 +262,6 @@ public function getOembedLinks()
*/
private function normalize($string)
{
return htmlentities(strip_tags($string), ENT_COMPAT, $this->encoding);
return htmlentities(strip_tags((string) $string), ENT_COMPAT, $this->encoding);
}
}
15 changes: 13 additions & 2 deletions tests/Twig/Extension/SeoExtensionTest.php
Expand Up @@ -85,13 +85,16 @@ public function testMetadatas()
'name' => ['foo' => ['bar "\'"', []]],
'schema' => [],
'charset' => ['UTF-8' => ['', []]],
'property' => [],
'property' => [
'og:image:width' => [848, []],
'og:type' => [new MetaTest(), []],
],
]));

$extension = new SeoExtension($page, 'UTF-8');

$this->assertSame(
"<meta name=\"foo\" content=\"bar &quot;'&quot;\" />\n<meta charset=\"UTF-8\" />\n",
"<meta name=\"foo\" content=\"bar &quot;'&quot;\" />\n<meta charset=\"UTF-8\" />\n<meta property=\"og:image:width\" content=\"848\" />\n<meta property=\"og:type\" content=\"article\" />\n",
$extension->getMetadatas()
);
}
Expand Down Expand Up @@ -147,3 +150,11 @@ public function testOEmbedLinks()
);
}
}

class MetaTest
{
public function __toString()
{
return 'article';
}
}

0 comments on commit b73bf69

Please sign in to comment.