0
0
mirror of https://github.com/ezyang/htmlpurifier.git synced 2024-11-08 14:58:42 +00:00

Properly handle context variables that are NULL.

Signed-off-by: Edward Z. Yang <ezyang@mit.edu>
This commit is contained in:
Edward Z. Yang 2013-10-13 13:05:21 -07:00
parent f17490f009
commit 82bcc62058
2 changed files with 12 additions and 4 deletions

View File

@ -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);
}
/**

View File

@ -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