From 70c39dd289d8fc59d3115fbc564c85a95deba1eb Mon Sep 17 00:00:00 2001 From: Daniel Kesselberg Date: Tue, 10 Aug 2021 18:36:17 +0200 Subject: [PATCH] Check if element without attribute is allowed Signed-off-by: Daniel Kesselberg --- library/HTMLPurifier/Filter/ExtractStyleBlocks.php | 4 ++++ .../HTMLPurifier/Filter/ExtractStyleBlocksTest.php | 13 +++++++++++++ 2 files changed, 17 insertions(+) diff --git a/library/HTMLPurifier/Filter/ExtractStyleBlocks.php b/library/HTMLPurifier/Filter/ExtractStyleBlocks.php index 66f70b0fc..090b115eb 100644 --- a/library/HTMLPurifier/Filter/ExtractStyleBlocks.php +++ b/library/HTMLPurifier/Filter/ExtractStyleBlocks.php @@ -243,6 +243,10 @@ public function cleanCSS($css, $config, $context) if ($y === '*' || isset($html_definition->info[$y = strtolower($y)])) { $nx = $y; } else { + $components2 = explode('[', $y); + if (count($components2) === 2 && isset($html_definition->info[$y2 = strtolower($components2[0])])) { + $nx = $y2; + } // $nx stays null; this matters // if we don't manage to find // any valid selector content, diff --git a/tests/HTMLPurifier/Filter/ExtractStyleBlocksTest.php b/tests/HTMLPurifier/Filter/ExtractStyleBlocksTest.php index e0c398f7e..168041a22 100644 --- a/tests/HTMLPurifier/Filter/ExtractStyleBlocksTest.php +++ b/tests/HTMLPurifier/Filter/ExtractStyleBlocksTest.php @@ -262,6 +262,19 @@ public function test_extractStyleBlocks_backtracking() $this->assertExtractStyleBlocks("" . $goo, $goo, array('')); } + public function test_cleanCSS_elementWithAttribute() + { + $this->assertCleanCSS( + "* img[tabindex=\"0\"] + div {\ntext-align:center\n}", + "* img + div {\ntext-align:center\n}" + ); + } + + public function test_cleanCSS_descendantSelector() + { + $this->assertCleanCSS("* img + div {\ntext-align:center\n}"); + } + } // vim: et sw=4 sts=4