diff --git a/src/Tests/MetatagFieldTest.php b/src/Tests/MetatagFieldTest.php index ea315d8..f9d3a74 100644 --- a/src/Tests/MetatagFieldTest.php +++ b/src/Tests/MetatagFieldTest.php @@ -176,5 +176,29 @@ class MetatagFieldTest extends WebTestBase { $this->assertResponse(200); $this->assertFieldByName('field_metatag[0][basic][description]', $global_values['description'], t('Description field has the global default as the field default does not define it.')); } + + /** + * Tests whether HTML is correctly removed from metatags + * + * Tests three values in metatags -- one without any HTML; one with raw html; and one with escaped HTML. + * To pass all HTML including escaped should be removed. + */ + public function testHTMLIsRemoved() { + $values = array( + 'abstract' => 'No HTML here', + 'description' => '

Surrounded by raw HTML

', + 'keywords' => '<html><body><p class="test">Surrounded by escaped HTML</p></body></html>', + ); + + $this->drupalPostForm('admin/config/search/metatag/global', $values, 'Save'); + $this->assertText('Saved the Global Metatag defaults.'); + drupal_flush_all_caches(); + $this->drupalGet('hit-a-404'); + $this->assertResponse(404); + + $this->assertRaw('', t('Test with no HTML content')); + $this->assertRaw('', t('Test with raw HTML content')); + $this->assertRaw('', t('Test with escaped HTML content')); + } } diff --git a/src/MetatagManager.php b/src/MetatagManager.php index 25f5802..b35d339 100644 --- a/src/MetatagManager.php +++ b/src/MetatagManager.php @@ -297,7 +297,11 @@ class MetatagManager implements MetatagManagerInterface { // @see @Robots::setValue(). $tag->setValue($value); $langcode = \Drupal::languageManager()->getCurrentLanguage(LanguageInterface::TYPE_CONTENT)->getId(); - $processed_value = PlainTextOutput::renderFromHtml($this->tokenService->tokenReplace($tag->value(), $token_replacements, array('langcode' => $langcode))); + if ($tag->image()) { + $processed_value = $this->tokenService->tokenReplace($tag->value(), $token_replacements, array('langcode' => $langcode)); + } else { + $processed_value = PlainTextOutput::renderFromHtml(htmlspecialchars_decode($this->tokenService->tokenReplace($tag->value(), $token_replacements, array('langcode' => $langcode)))); + } // Now store the value with processed tokens back into the plugin. $tag->setValue($processed_value); diff --git a/src/Plugin/metatag/Tag/MetaNameBase.php b/src/Plugin/metatag/Tag/MetaNameBase.php index 58d41ff..0009f43 100644 --- a/src/Plugin/metatag/Tag/MetaNameBase.php +++ b/src/Plugin/metatag/Tag/MetaNameBase.php @@ -202,6 +202,15 @@ abstract class MetaNameBase extends PluginBase { // If this contains embedded image tags, extract the image URLs. if ($this->image()) { + // If image tag src is relative (starts with /), convert to an absolute link + global $base_url; + if(strpos($value, '