From b6e222cbc2f61516e9eacd252a6b9603c190d290 Mon Sep 17 00:00:00 2001 From: "Edward Z. Yang" Date: Wed, 20 Dec 2006 23:51:09 +0000 Subject: [PATCH] [1.3.2] Added purifyArray(), which takes a list of HTML and purifies it all git-svn-id: http://htmlpurifier.org/svnroot/htmlpurifier/trunk@615 48356398-32a2-884e-a903-53898d9a118a --- NEWS | 1 + TODO | 1 - library/HTMLPurifier.php | 18 +++++++++++++++++- tests/HTMLPurifier/Test.php | 15 +++++++++++++++ 4 files changed, 33 insertions(+), 2 deletions(-) diff --git a/NEWS b/NEWS index 9ac40031..4ef5ab25 100644 --- a/NEWS +++ b/NEWS @@ -19,6 +19,7 @@ NEWS ( CHANGELOG and HISTORY ) HTMLPurifier ! Context object now accessible to outside ! Added enduser-youtube.html, explains how to embed YouTube videos. See also corresponding smoketest preserveYouTube.php. +! Added purifyArray(), which takes a list of HTML and purifies it all - printDefinition.php: added labels, added better clarification . HTMLPurifier_Config::create() added, takes mixed variable and converts into a HTMLPurifier_Config object. diff --git a/TODO b/TODO index 5b8620eb..bc34cee8 100644 --- a/TODO +++ b/TODO @@ -84,7 +84,6 @@ Requested 3. Extend the tag exclusion system to specify whether or not the contents should be dropped or not (currently, there's code that could do something like this if it didn't drop the inner text too.) - - Accept array input, by iterating and purifying all of the items - More user-friendly warnings when %HTML.Allow* attempts to specify a tag or attribute that is not supported - Allow specifying global attributes on a tag-by-tag basis in diff --git a/library/HTMLPurifier.php b/library/HTMLPurifier.php index f335b2b3..df1088c2 100644 --- a/library/HTMLPurifier.php +++ b/library/HTMLPurifier.php @@ -107,7 +107,6 @@ class HTMLPurifier $config = $config ? HTMLPurifier_Config::create($config) : $this->config; - $context =& new HTMLPurifier_Context(); $html = $this->encoder->convertToUTF8($html, $config, $context); @@ -131,6 +130,23 @@ class HTMLPurifier return $html; } + /** + * Filters an array of HTML snippets + * @param $config Optional HTMLPurifier_Config object for this operation. + * See HTMLPurifier::purify() for more details. + * @return Array of purified HTML + */ + 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); + $context_array[$key] = $this->context; + } + $this->context = $context_array; + return $array_of_html; + } + + } ?> \ No newline at end of file diff --git a/tests/HTMLPurifier/Test.php b/tests/HTMLPurifier/Test.php index 9760c6cb..daa39f53 100644 --- a/tests/HTMLPurifier/Test.php +++ b/tests/HTMLPurifier/Test.php @@ -68,6 +68,21 @@ class HTMLPurifier_Test extends UnitTestCase } + function test_purifyArray() { + + $this->purifier = new HTMLPurifier(); + + $this->assertEqual( + $this->purifier->purifyArray( + array('Good', 'Sketchy', 'foo' => '') + ), + array('Good', 'Sketchy', 'foo' => 'bad') + ); + + $this->assertIsA($this->purifier->context, 'array'); + + } + } ?> \ No newline at end of file