mirror of
https://github.com/ezyang/htmlpurifier.git
synced 2024-12-22 16:31:53 +00: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:
parent
f5cd2c07ea
commit
5cfecebb33
2
NEWS
2
NEWS
@ -15,6 +15,8 @@ NEWS ( CHANGELOG and HISTORY ) HTMLPurifier
|
|||||||
does not do the "right thing" with characters not supported in the output
|
does not do the "right thing" with characters not supported in the output
|
||||||
set.
|
set.
|
||||||
- Spellcheck UTF-8: The Secret To Character Encoding
|
- Spellcheck UTF-8: The Secret To Character Encoding
|
||||||
|
- Fix improper removal of the contents of elements with only whitespace. Thanks
|
||||||
|
Eric Wald for reporting.
|
||||||
. Add verbose mode to command line test runner, use (--verbose)
|
. Add verbose mode to command line test runner, use (--verbose)
|
||||||
. Turn on unit tests for UnitConverter
|
. Turn on unit tests for UnitConverter
|
||||||
. Fix missing version number in configuration %Attr.DefaultImageAlt (added 3.2.0)
|
. Fix missing version number in configuration %Attr.DefaultImageAlt (added 3.2.0)
|
||||||
|
1
TODO
1
TODO
@ -15,7 +15,6 @@ afraid to cast your vote for the next feature to be implemented!
|
|||||||
prevent structures from being parsed and serialized multiple times.
|
prevent structures from being parsed and serialized multiple times.
|
||||||
- Built-in support for target="_blank" on all external links
|
- Built-in support for target="_blank" on all external links
|
||||||
- Allow <a id="asdf" name="asdf">
|
- Allow <a id="asdf" name="asdf">
|
||||||
- Implement overflow CSS property (as per jlp09550)
|
|
||||||
- Convert configuration to allow an arbitrary number of namespaces;
|
- Convert configuration to allow an arbitrary number of namespaces;
|
||||||
then rename as appropriate.
|
then rename as appropriate.
|
||||||
|
|
||||||
|
@ -13,8 +13,10 @@ class HTMLPurifier_ChildDef_Optional extends HTMLPurifier_ChildDef_Required
|
|||||||
public $type = 'optional';
|
public $type = 'optional';
|
||||||
public function validateChildren($tokens_of_children, $config, $context) {
|
public function validateChildren($tokens_of_children, $config, $context) {
|
||||||
$result = parent::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 ($result === false) {
|
||||||
if (empty($tokens_of_children)) return true;
|
if (empty($tokens_of_children)) return true;
|
||||||
|
elseif ($this->whitespace) return $tokens_of_children;
|
||||||
else return array();
|
else return array();
|
||||||
}
|
}
|
||||||
return $result;
|
return $result;
|
||||||
|
@ -10,6 +10,10 @@ class HTMLPurifier_ChildDef_Required extends HTMLPurifier_ChildDef
|
|||||||
* @public
|
* @public
|
||||||
*/
|
*/
|
||||||
public $elements = array();
|
public $elements = array();
|
||||||
|
/**
|
||||||
|
* Whether or not the last passed node was all whitespace.
|
||||||
|
*/
|
||||||
|
protected $whitespace = false;
|
||||||
/**
|
/**
|
||||||
* @param $elements List of allowed element names (lowercase).
|
* @param $elements List of allowed element names (lowercase).
|
||||||
*/
|
*/
|
||||||
@ -31,6 +35,9 @@ class HTMLPurifier_ChildDef_Required extends HTMLPurifier_ChildDef
|
|||||||
public $allow_empty = false;
|
public $allow_empty = false;
|
||||||
public $type = 'required';
|
public $type = 'required';
|
||||||
public function validateChildren($tokens_of_children, $config, $context) {
|
public function validateChildren($tokens_of_children, $config, $context) {
|
||||||
|
// Flag for subclasses
|
||||||
|
$this->whitespace = false;
|
||||||
|
|
||||||
// if there are no tokens, delete parent node
|
// if there are no tokens, delete parent node
|
||||||
if (empty($tokens_of_children)) return false;
|
if (empty($tokens_of_children)) return false;
|
||||||
|
|
||||||
@ -98,7 +105,10 @@ class HTMLPurifier_ChildDef_Required extends HTMLPurifier_ChildDef
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (empty($result)) return false;
|
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;
|
if ($tokens_of_children == $result) return true;
|
||||||
return $result;
|
return $result;
|
||||||
}
|
}
|
||||||
|
@ -20,5 +20,12 @@ class HTMLPurifier_ChildDef_OptionalTest extends HTMLPurifier_ChildDefHarness
|
|||||||
$this->assertResult('');
|
$this->assertResult('');
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
function testWhitespace() {
|
||||||
|
$this->assertResult(' ');
|
||||||
|
}
|
||||||
|
|
||||||
|
function testMultipleWhitespace() {
|
||||||
|
$this->assertResult(' ');
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
3
tests/HTMLPurifier/HTMLT/whitespace-preserve.htmlt
Normal file
3
tests/HTMLPurifier/HTMLT/whitespace-preserve.htmlt
Normal file
@ -0,0 +1,3 @@
|
|||||||
|
--HTML--
|
||||||
|
Foo<b> </b>bar
|
||||||
|
|
Loading…
Reference in New Issue
Block a user