From d8a6361244893a4395f8cdd037e643d30314d235 Mon Sep 17 00:00:00 2001 From: "Edward Z. Yang" Date: Mon, 30 Apr 2007 01:14:21 +0000 Subject: [PATCH] [1.6.1] Empty strings get converted to empty arrays instead of arrays with an empty string in them. git-svn-id: http://htmlpurifier.org/svnroot/htmlpurifier/trunk@1000 48356398-32a2-884e-a903-53898d9a118a --- NEWS | 2 ++ library/HTMLPurifier/ConfigSchema.php | 4 ++++ tests/HTMLPurifier/ConfigSchemaTest.php | 3 +++ 3 files changed, 9 insertions(+) diff --git a/NEWS b/NEWS index 6981cc82..4013cecc 100644 --- a/NEWS +++ b/NEWS @@ -20,6 +20,8 @@ NEWS ( CHANGELOG and HISTORY ) HTMLPurifier - Possibly fatal bug with __autoload() fixed in module manager - Invert HTMLModuleManager->addModule() processing order to check prefixes first and then the literal module +- Empty strings get converted to empty arrays instead of arrays with + an empty string in them. . Demo script removed: it has been added to the website's repository . Basic.php script modified to work out of the box diff --git a/library/HTMLPurifier/ConfigSchema.php b/library/HTMLPurifier/ConfigSchema.php index 9f1f3e3e..940e8e61 100644 --- a/library/HTMLPurifier/ConfigSchema.php +++ b/library/HTMLPurifier/ConfigSchema.php @@ -334,6 +334,10 @@ class HTMLPurifier_ConfigSchema { case 'hash': case 'lookup': if (is_string($var)) { + // special case: technically, this is an array with + // a single empty string item, but having an empty + // array is more intuitive + if ($var == '') return array(); // simplistic string to array method that only works // for simple lists of tag names or alphanumeric characters $var = explode(',',$var); diff --git a/tests/HTMLPurifier/ConfigSchemaTest.php b/tests/HTMLPurifier/ConfigSchemaTest.php index 1f1f7034..8a20988f 100644 --- a/tests/HTMLPurifier/ConfigSchemaTest.php +++ b/tests/HTMLPurifier/ConfigSchemaTest.php @@ -277,14 +277,17 @@ class HTMLPurifier_ConfigSchemaTest extends UnitTestCase $this->assertValid(array('1', '2', '3'), 'list'); $this->assertValid('foo,bar, cow', 'list', array('foo', 'bar', 'cow')); + $this->assertValid('', 'list', array()); $this->assertValid(array('1' => true, '2' => true), 'lookup'); $this->assertValid(array('1', '2'), 'lookup', array('1' => true, '2' => true)); $this->assertValid('foo,bar', 'lookup', array('foo' => true, 'bar' => true)); + $this->assertValid('', 'lookup', array()); $this->assertValid(array('foo' => 'bar'), 'hash'); $this->assertValid(array(1 => 'moo'), 'hash'); $this->assertInvalid(array(0 => 'moo'), 'hash'); + $this->assertValid('', 'hash', array()); $this->assertValid(23, 'mixed');