summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorNathaniel Catchpole2017-11-13 13:35:04 (GMT)
committerNathaniel Catchpole2017-11-13 13:35:04 (GMT)
commitffa979ba1c6580b1db6b99c291a496e2c21a2b89 (patch)
treee6f8ea206079b58b10c5ceb569b8311fb5fc2831
parent623461231beff5038f72aacacf20cca4ccd1e564 (diff)
Issue #2563069 by DuaelFr, ecarty, idebr: Unclosed conditional comments in html tag result in broken html head
-rw-r--r--core/lib/Drupal/Core/Render/Element/HtmlTag.php10
-rw-r--r--core/tests/Drupal/Tests/Core/Render/Element/HtmlTagTest.php16
2 files changed, 21 insertions, 5 deletions
diff --git a/core/lib/Drupal/Core/Render/Element/HtmlTag.php b/core/lib/Drupal/Core/Render/Element/HtmlTag.php
index 2413784..98cf636 100644
--- a/core/lib/Drupal/Core/Render/Element/HtmlTag.php
+++ b/core/lib/Drupal/Core/Render/Element/HtmlTag.php
@@ -87,19 +87,19 @@ class HtmlTag extends RenderElement {
$escaped_tag = HtmlUtility::escape($element['#tag']);
$open_tag = '<' . $escaped_tag . $attributes;
$close_tag = '</' . $escaped_tag . ">\n";
- $prefix = isset($element['#prefix']) ? $element['#prefix'] . $open_tag : $open_tag;
- $suffix = isset($element['#suffix']) ? $close_tag . $element['#suffix'] : $close_tag;
// Construct a void element.
if (in_array($element['#tag'], self::$voidElements)) {
- $prefix .= " />\n";
- $suffix = '';
+ $open_tag .= ' />';
+ $close_tag = "\n";
}
// Construct all other elements.
else {
- $prefix .= '>';
+ $open_tag .= '>';
$markup = $element['#value'] instanceof MarkupInterface ? $element['#value'] : Xss::filterAdmin($element['#value']);
$element['#markup'] = Markup::create($markup);
}
+ $prefix = isset($element['#prefix']) ? $element['#prefix'] . $open_tag : $open_tag;
+ $suffix = isset($element['#suffix']) ? $close_tag . $element['#suffix'] : $close_tag;
if (!empty($element['#noscript'])) {
$prefix = '<noscript>' . $prefix;
$suffix .= '</noscript>';
diff --git a/core/tests/Drupal/Tests/Core/Render/Element/HtmlTagTest.php b/core/tests/Drupal/Tests/Core/Render/Element/HtmlTagTest.php
index 03f4232..51ac995 100644
--- a/core/tests/Drupal/Tests/Core/Render/Element/HtmlTagTest.php
+++ b/core/tests/Drupal/Tests/Core/Render/Element/HtmlTagTest.php
@@ -202,6 +202,22 @@ class HtmlTagTest extends RendererTestBase {
];
$tags['linearGradient'] = [$element, '<linearGradient><stop offset="5%" stop-color="#F60" />' . "\n" . '<stop offset="95%" stop-color="#FF6" />' . "\n" . '</linearGradient>' . "\n"];
+ // Simple link.
+ $element = [
+ '#tag' => 'link',
+ ];
+ $tags['link'] = [HtmlTag::preRenderConditionalComments($element), '<link />' . "\n"];
+
+ // Conditional link.
+ $element = [
+ '#tag' => 'link',
+ '#browsers' => [
+ 'IE' => TRUE,
+ '!IE' => FALSE,
+ ],
+ ];
+ $tags['conditional-link'] = [HtmlTag::preRenderConditionalComments($element), "\n" . '<!--[if IE]>' . "\n" . '<link />' . "\n" . '<![endif]-->' . "\n"];
+
return $tags;
}