From 3b3a9825a4672c57534d5b9002bafcbdab57516a Mon Sep 17 00:00:00 2001 From: Mark Carver Date: Thu, 29 May 2014 10:38:58 -0500 Subject: [PATCH] Issue #552478 by pwolanin, sun, effulgentsia, dropcube, Mark Carver, ohnobinki, samj, Wim Leers: Fixed Remove "self-closing" and restrict no "closing tags" to only void elements in html_tag. --- core/includes/common.inc | 15 ++++++++-- .../src/Tests/Common/CascadingStylesheetsTest.php | 2 +- .../src/Tests/Common/RenderElementTypesTest.php | 32 ++++++++++++++++++---- 3 files changed, 40 insertions(+), 9 deletions(-) diff --git a/core/includes/common.inc b/core/includes/common.inc index 349449a..7fc52a5 100644 --- a/core/includes/common.inc +++ b/core/includes/common.inc @@ -2864,9 +2864,20 @@ function drupal_pre_render_conditional_comments($elements) { */ function drupal_pre_render_html_tag($element) { $attributes = isset($element['#attributes']) ? new Attribute($element['#attributes']) : ''; - if (!isset($element['#value'])) { - $markup = '<' . $element['#tag'] . $attributes . " />\n"; + + // Void elements do not contain values or closing tags. + // @see http://www.w3.org/TR/html5/syntax.html#syntax-start-tag + // @see http://www.w3.org/TR/html5/syntax.html#void-elements + static $void_elements = array( + 'area', 'base', 'br', 'col', 'embed', 'hr', 'img', 'input', + 'keygen', 'link', 'meta', 'param', 'source', 'track', 'wbr', + ); + + // Construct a void element. + if (in_array($element['#tag'], $void_elements)) { + $markup = '<' . $element['#tag'] . $attributes . ">\n"; } + // Construct all other elements. else { $markup = '<' . $element['#tag'] . $attributes . '>'; if (isset($element['#value_prefix'])) { diff --git a/core/modules/system/src/Tests/Common/CascadingStylesheetsTest.php b/core/modules/system/src/Tests/Common/CascadingStylesheetsTest.php index 97b1fc6..4537019 100644 --- a/core/modules/system/src/Tests/Common/CascadingStylesheetsTest.php +++ b/core/modules/system/src/Tests/Common/CascadingStylesheetsTest.php @@ -78,7 +78,7 @@ function testRenderFile() { $this->assertTrue(strpos($styles, $css) > 0, 'Rendered CSS includes the added stylesheet.'); // Verify that newlines are properly added inside style tags. $query_string = $this->container->get('state')->get('system.css_js_query_string') ?: '0'; - $css_processed = ''; + $css_processed = ''; $this->assertEqual(trim($styles), $css_processed, 'Rendered CSS includes newlines inside style tags for JavaScript use.'); } diff --git a/core/modules/system/src/Tests/Common/RenderElementTypesTest.php b/core/modules/system/src/Tests/Common/RenderElementTypesTest.php index 15a1904..2a2e6b2 100644 --- a/core/modules/system/src/Tests/Common/RenderElementTypesTest.php +++ b/core/modules/system/src/Tests/Common/RenderElementTypesTest.php @@ -89,22 +89,42 @@ function testContainer() { * Tests system #type 'html_tag'. */ function testHtmlTag() { - // Test auto-closure meta tag generation. + // Test void element. $this->assertElements(array( '#type' => 'html_tag', '#tag' => 'meta', + '#value' => 'ignored', + '#value_prefix' => 'ignored', + '#value_suffix' => 'ignored', '#attributes' => array( 'name' => 'description', 'content' => 'Drupal test', ), - ), '' . "\n", "#type 'html_tag' auto-closure meta tag generation"); + ), '' . "\n", "#type 'html_tag', void element renders properly"); - // Test title tag generation. + // Test non-void element. $this->assertElements(array( '#type' => 'html_tag', - '#tag' => 'title', - '#value' => 'title test', - ), "title test\n", "#type 'html_tag' title tag generation"); + '#tag' => 'section', + '#value' => 'value', + '#value_prefix' => 'value_prefix|', + '#value_suffix' => '|value_suffix', + '#attributes' => array( + 'class' => array('unicorns'), + ), + ), '
value_prefix|value|value_suffix
' . "\n", "#type 'html_tag', non-void element renders properly"); + + // Test empty void element tag. + $this->assertElements(array( + '#type' => 'html_tag', + '#tag' => 'link', + ), "\n", "#type 'html_tag' empty void element renders properly"); + + // Test empty non-void element tag. + $this->assertElements(array( + '#type' => 'html_tag', + '#tag' => 'section', + ), "
\n", "#type 'html_tag' empty non-void element renders properly"); } } -- 1.9.1