1
0
mirror of https://github.com/ezyang/htmlpurifier.git synced 2025-07-10 17:26:25 +02:00

Fix bug involving whitespace-only nodes. Thanks Eric Wald for reporting.

Signed-off-by: Edward Z. Yang <edwardzyang@thewritingpot.com>
This commit is contained in:
Edward Z. Yang
2008-12-02 20:13:47 -05:00
parent f5cd2c07ea
commit 5cfecebb33
6 changed files with 26 additions and 3 deletions

View File

@ -13,8 +13,10 @@ class HTMLPurifier_ChildDef_Optional extends HTMLPurifier_ChildDef_Required
public $type = 'optional';
public function validateChildren($tokens_of_children, $config, $context) {
$result = parent::validateChildren($tokens_of_children, $config, $context);
// we assume that $tokens_of_children is not modified
if ($result === false) {
if (empty($tokens_of_children)) return true;
elseif ($this->whitespace) return $tokens_of_children;
else return array();
}
return $result;

View File

@ -10,6 +10,10 @@ class HTMLPurifier_ChildDef_Required extends HTMLPurifier_ChildDef
* @public
*/
public $elements = array();
/**
* Whether or not the last passed node was all whitespace.
*/
protected $whitespace = false;
/**
* @param $elements List of allowed element names (lowercase).
*/
@ -31,6 +35,9 @@ class HTMLPurifier_ChildDef_Required extends HTMLPurifier_ChildDef
public $allow_empty = false;
public $type = 'required';
public function validateChildren($tokens_of_children, $config, $context) {
// Flag for subclasses
$this->whitespace = false;
// if there are no tokens, delete parent node
if (empty($tokens_of_children)) return false;
@ -98,7 +105,10 @@ class HTMLPurifier_ChildDef_Required extends HTMLPurifier_ChildDef
}
}
if (empty($result)) return false;
if ($all_whitespace) return false;
if ($all_whitespace) {
$this->whitespace = true;
return false;
}
if ($tokens_of_children == $result) return true;
return $result;
}