From 82bcc6205885c792890cf13b87192a4ce90f96e4 Mon Sep 17 00:00:00 2001 From: "Edward Z. Yang" Date: Sun, 13 Oct 2013 13:05:21 -0700 Subject: [PATCH] Properly handle context variables that are NULL. Signed-off-by: Edward Z. Yang --- library/HTMLPurifier/Context.php | 8 ++++---- tests/HTMLPurifier/ContextTest.php | 8 ++++++++ 2 files changed, 12 insertions(+), 4 deletions(-) diff --git a/library/HTMLPurifier/Context.php b/library/HTMLPurifier/Context.php index 8cc443f0..00e509c8 100644 --- a/library/HTMLPurifier/Context.php +++ b/library/HTMLPurifier/Context.php @@ -23,7 +23,7 @@ class HTMLPurifier_Context */ public function register($name, &$ref) { - if (isset($this->_storage[$name])) { + if (array_key_exists($name, $this->_storage)) { trigger_error( "Name $name produces collision, cannot re-register", E_USER_ERROR @@ -41,7 +41,7 @@ class HTMLPurifier_Context */ public function &get($name, $ignore_error = false) { - if (!isset($this->_storage[$name])) { + if (!array_key_exists($name, $this->_storage)) { if (!$ignore_error) { trigger_error( "Attempted to retrieve non-existent variable $name", @@ -60,7 +60,7 @@ class HTMLPurifier_Context */ public function destroy($name) { - if (!isset($this->_storage[$name])) { + if (!array_key_exists($name, $this->_storage)) { trigger_error( "Attempted to destroy non-existent variable $name", E_USER_ERROR @@ -77,7 +77,7 @@ class HTMLPurifier_Context */ public function exists($name) { - return isset($this->_storage[$name]); + return array_key_exists($name, $this->_storage); } /** diff --git a/tests/HTMLPurifier/ContextTest.php b/tests/HTMLPurifier/ContextTest.php index 72d22caa..8baaf27e 100644 --- a/tests/HTMLPurifier/ContextTest.php +++ b/tests/HTMLPurifier/ContextTest.php @@ -80,6 +80,14 @@ class HTMLPurifier_ContextTest extends HTMLPurifier_Harness } + public function testNull() { + $context = new HTMLPurifier_Context(); + $var = NULL; + $context->register('var', $var); + $this->assertNull($context->get('var')); + $context->destroy('var'); + } + } // vim: et sw=4 sts=4