From 29c3e56f15ca245976fe334e7d0570dee8a41a5d Mon Sep 17 00:00:00 2001
From: omniError
Date: Thu, 5 May 2022 12:18:14 -0500
Subject: [PATCH] [HtmlSanitizer] Fix node renderer handling of self-closing
(void) elements
---
.../Tests/HtmlSanitizerAllTest.php | 14 +++++++++++--
.../HtmlSanitizer/Visitor/Node/Node.php | 21 ++++++++++++++++++-
2 files changed, 32 insertions(+), 3 deletions(-)
diff --git a/src/Symfony/Component/HtmlSanitizer/Tests/HtmlSanitizerAllTest.php b/src/Symfony/Component/HtmlSanitizer/Tests/HtmlSanitizerAllTest.php
index 7e53d8c3a3207..18c175ba296e8 100644
--- a/src/Symfony/Component/HtmlSanitizer/Tests/HtmlSanitizerAllTest.php
+++ b/src/Symfony/Component/HtmlSanitizer/Tests/HtmlSanitizerAllTest.php
@@ -237,16 +237,21 @@ public function provideSanitizeBody()
],
[
'',
- ' ',
+ '
',
],
[
'',
- ' ',
+ ' ',
],
[
' ',
' ',
],
+ [
+ ' ',
+ ' ',
+ ],
+
[
' ',
'',
@@ -445,6 +450,11 @@ public function provideSanitizeBody()
'Lorem ipsum ',
'Lorem ipsum ',
],
+ [
+ ' ',
+ ' ',
+ ],
+
[
'Lorem ipsum ',
'Lorem ipsum ',
diff --git a/src/Symfony/Component/HtmlSanitizer/Visitor/Node/Node.php b/src/Symfony/Component/HtmlSanitizer/Visitor/Node/Node.php
index 76838028dbc0d..8a4e5c32aa7ac 100644
--- a/src/Symfony/Component/HtmlSanitizer/Visitor/Node/Node.php
+++ b/src/Symfony/Component/HtmlSanitizer/Visitor/Node/Node.php
@@ -20,6 +20,25 @@
*/
final class Node implements NodeInterface
{
+ // HTML5 elements which are self-closing
+ private const VOID_ELEMENTS = [
+ 'area' => true,
+ 'base' => true,
+ 'br' => true,
+ 'col' => true,
+ 'embed' => true,
+ 'hr' => true,
+ 'img' => true,
+ 'input' => true,
+ 'keygen' => true,
+ 'link' => true,
+ 'meta' => true,
+ 'param' => true,
+ 'source' => true,
+ 'track' => true,
+ 'wbr' => true,
+ ];
+
private NodeInterface $parent;
private string $tagName;
private array $attributes = [];
@@ -56,7 +75,7 @@ public function addChild(NodeInterface $node): void
public function render(): string
{
- if (!$this->children) {
+ if (isset(self::VOID_ELEMENTS[$this->tagName])) {
return '<'.$this->tagName.$this->renderAttributes().' />';
}
pFad - Phonifier reborn
Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.
Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.
Alternative Proxies:
Alternative Proxy
pFad Proxy
pFad v3 Proxy
pFad v4 Proxy