From b91833877a4cdc541c9ae08a93d6ad6d0e9485a0 Mon Sep 17 00:00:00 2001 From: Sandro Miguel Marques Date: Sun, 14 Jul 2019 19:10:33 +0100 Subject: [PATCH] Method purifyArray() updated (#143) * Methof purifyArray() updated Now it works with multidimensional arrays * Add test case. Signed-off-by: Edward Z. Yang --- library/HTMLPurifier.php | 10 +++++++--- tests/HTMLPurifierTest.php | 10 ++++++++++ 2 files changed, 17 insertions(+), 3 deletions(-) diff --git a/library/HTMLPurifier.php b/library/HTMLPurifier.php index bada5188..76abb544 100644 --- a/library/HTMLPurifier.php +++ b/library/HTMLPurifier.php @@ -240,12 +240,16 @@ class HTMLPurifier public function purifyArray($array_of_html, $config = null) { $context_array = array(); - foreach ($array_of_html as $key => $html) { - $array_of_html[$key] = $this->purify($html, $config); + foreach($array_of_html as $key=>$value){ + if (is_array($value)) { + $array[$key] = $this->purifyArray($value, $config); + } else { + $array[$key] = $this->purify($value, $config); + } $context_array[$key] = $this->context; } $this->context = $context_array; - return $array_of_html; + return $array; } /** diff --git a/tests/HTMLPurifierTest.php b/tests/HTMLPurifierTest.php index 1fbcddf8..2d28bc3c 100644 --- a/tests/HTMLPurifierTest.php +++ b/tests/HTMLPurifierTest.php @@ -22,6 +22,16 @@ class HTMLPurifierTest extends HTMLPurifier_Harness } + public function test_purifyArray_nested() + { + $this->assertIdentical( + $this->purifier->purifyArray( + array('Good', 'Sketchy', 'foo' => array('bar' => '')) + ), + array('Good', 'Sketchy', 'foo' => array('bar' => '')) + ); + } + public function testGetInstance() { $purifier = HTMLPurifier::getInstance();