mirror of
https://github.com/ezyang/htmlpurifier.git
synced 2024-12-31 20:01:52 +00:00
Add boolean value flag for PEARSax3 for testing if a token is empty.
Signed-off-by: Brian DeRocher <brian@derocher.org> Signed-off-by: Edward Z. Yang <ezyang@mit.edu>
This commit is contained in:
parent
ac18672aba
commit
b3ca1498c2
@ -26,6 +26,7 @@ class HTMLPurifier_Lexer_PEARSax3 extends HTMLPurifier_Lexer
|
|||||||
* Internal accumulator array for SAX parsers.
|
* Internal accumulator array for SAX parsers.
|
||||||
*/
|
*/
|
||||||
protected $tokens = array();
|
protected $tokens = array();
|
||||||
|
protected $last_token_was_empty;
|
||||||
|
|
||||||
private $parent_handler;
|
private $parent_handler;
|
||||||
private $stack = array();
|
private $stack = array();
|
||||||
@ -33,6 +34,7 @@ class HTMLPurifier_Lexer_PEARSax3 extends HTMLPurifier_Lexer
|
|||||||
public function tokenizeHTML($string, $config, $context) {
|
public function tokenizeHTML($string, $config, $context) {
|
||||||
|
|
||||||
$this->tokens = array();
|
$this->tokens = array();
|
||||||
|
$this->last_token_was_empty = false;
|
||||||
|
|
||||||
$string = $this->normalize($string, $config, $context);
|
$string = $this->normalize($string, $config, $context);
|
||||||
|
|
||||||
@ -65,6 +67,7 @@ class HTMLPurifier_Lexer_PEARSax3 extends HTMLPurifier_Lexer
|
|||||||
}
|
}
|
||||||
if ($closed) {
|
if ($closed) {
|
||||||
$this->tokens[] = new HTMLPurifier_Token_Empty($name, $attrs);
|
$this->tokens[] = new HTMLPurifier_Token_Empty($name, $attrs);
|
||||||
|
$this->last_token_was_empty = true;
|
||||||
} else {
|
} else {
|
||||||
$this->tokens[] = new HTMLPurifier_Token_Start($name, $attrs);
|
$this->tokens[] = new HTMLPurifier_Token_Start($name, $attrs);
|
||||||
}
|
}
|
||||||
@ -79,7 +82,8 @@ class HTMLPurifier_Lexer_PEARSax3 extends HTMLPurifier_Lexer
|
|||||||
// HTMLSax3 seems to always send empty tags an extra close tag
|
// HTMLSax3 seems to always send empty tags an extra close tag
|
||||||
// check and ignore if you see it:
|
// check and ignore if you see it:
|
||||||
// [TESTME] to make sure it doesn't overreach
|
// [TESTME] to make sure it doesn't overreach
|
||||||
if ($this->tokens[count($this->tokens)-1] instanceof HTMLPurifier_Token_Empty) {
|
if ($this->last_token_was_empty) {
|
||||||
|
$this->last_token_was_empty = false;
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
$this->tokens[] = new HTMLPurifier_Token_End($name);
|
$this->tokens[] = new HTMLPurifier_Token_End($name);
|
||||||
@ -91,6 +95,7 @@ class HTMLPurifier_Lexer_PEARSax3 extends HTMLPurifier_Lexer
|
|||||||
* Data event handler, interface is defined by PEAR package.
|
* Data event handler, interface is defined by PEAR package.
|
||||||
*/
|
*/
|
||||||
public function dataHandler(&$parser, $data) {
|
public function dataHandler(&$parser, $data) {
|
||||||
|
$this->last_token_was_empty = false;
|
||||||
$this->tokens[] = new HTMLPurifier_Token_Text($data);
|
$this->tokens[] = new HTMLPurifier_Token_Text($data);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
@ -111,6 +116,7 @@ class HTMLPurifier_Lexer_PEARSax3 extends HTMLPurifier_Lexer
|
|||||||
} else {
|
} else {
|
||||||
$this->tokens[] = new HTMLPurifier_Token_Comment($data);
|
$this->tokens[] = new HTMLPurifier_Token_Comment($data);
|
||||||
}
|
}
|
||||||
|
$this->last_token_was_empty = false;
|
||||||
}
|
}
|
||||||
// CDATA is handled elsewhere, but if it was handled here:
|
// CDATA is handled elsewhere, but if it was handled here:
|
||||||
//if (strpos($data, '[CDATA[') === 0) {
|
//if (strpos($data, '[CDATA[') === 0) {
|
||||||
|
Loading…
Reference in New Issue
Block a user