1
0
mirror of https://github.com/ezyang/htmlpurifier.git synced 2025-08-03 12:47:56 +02:00

Method purifyArray() updated (#143)

* Methof purifyArray() updated

Now it works with multidimensional arrays

* Add test case.

Signed-off-by: Edward Z. Yang <ezyang@mit.edu>
This commit is contained in:
Sandro Miguel Marques
2019-07-14 19:10:33 +01:00
committed by Edward Z. Yang
parent abba77a80b
commit b91833877a
2 changed files with 17 additions and 3 deletions

View File

@@ -240,12 +240,16 @@ class HTMLPurifier
public function purifyArray($array_of_html, $config = null) public function purifyArray($array_of_html, $config = null)
{ {
$context_array = array(); $context_array = array();
foreach ($array_of_html as $key => $html) { foreach($array_of_html as $key=>$value){
$array_of_html[$key] = $this->purify($html, $config); if (is_array($value)) {
$array[$key] = $this->purifyArray($value, $config);
} else {
$array[$key] = $this->purify($value, $config);
}
$context_array[$key] = $this->context; $context_array[$key] = $this->context;
} }
$this->context = $context_array; $this->context = $context_array;
return $array_of_html; return $array;
} }
/** /**

View File

@@ -22,6 +22,16 @@ class HTMLPurifierTest extends HTMLPurifier_Harness
} }
public function test_purifyArray_nested()
{
$this->assertIdentical(
$this->purifier->purifyArray(
array('Good', '<b>Sketchy', 'foo' => array('bar' => '<script>bad</script>'))
),
array('Good', '<b>Sketchy</b>', 'foo' => array('bar' => ''))
);
}
public function testGetInstance() public function testGetInstance()
{ {
$purifier = HTMLPurifier::getInstance(); $purifier = HTMLPurifier::getInstance();