Fix #77040: tidyNode::isHtml() is completely broken

The documentation of `tidyNode::isHtml()` states that this method
"checks if a node is part of a HTML document".  That is, of course,
nonsense, since a tidyNode is "an HTML node in an HTML file, as
detected by tidy."

What this method is actually supposed to do is to check whether a node
is an element (unless it is the root element).  This has been broken by
commit d8eeb8e[1], which assumed that `enum TidyNodeType` would
represent flags of a bitmask, what it does not.

[1] <http://git.php.net/?p=php-src.git;a=commit;h=d8eeb8e28673236bca3f066ded75037a5bdf6378>

Closes GH-6290.
This commit is contained in:
Christoph M. Becker 2020-10-07 12:45:43 +02:00
parent e857dfa7cc
commit e68acd031d
3 changed files with 37 additions and 4 deletions

3
NEWS
View file

@ -35,6 +35,9 @@ PHP NEWS
. Fixed bug #76943 (Inconsistent stream_wrapper_restore() errors). (cmb) . Fixed bug #76943 (Inconsistent stream_wrapper_restore() errors). (cmb)
. Fixed bug #76735 (Incorrect message in fopen on invalid mode). (cmb) . Fixed bug #76735 (Incorrect message in fopen on invalid mode). (cmb)
- Tidy:
. Fixed bug #77040 (tidyNode::isHtml() is completely broken). (cmb)
01 Oct 2020, PHP 7.3.23 01 Oct 2020, PHP 7.3.23
- Core: - Core:

View file

@ -0,0 +1,27 @@
--TEST--
Bug #77040 (tidyNode::isHtml() is completely broken)
--SKIPIF--
<?php
if (!extension_loaded('tidy')) die('skip tidy extension not available');
?>
--FILE--
<?php
$tidy = new tidy;
$tidy->parseString("<p>text</p><p><![CDATA[cdata]]></p>");
$p = $tidy->body()->child[0];
var_dump($p->type === TIDY_NODETYPE_START);
var_dump($p->isHtml());
$text = $p->child[0];
var_dump($text->type === TIDY_NODETYPE_TEXT);
var_dump($text->isHtml());
$cdata = $tidy->body()->child[1]->child[0];
var_dump($cdata->type === TIDY_NODETYPE_CDATA);
var_dump($cdata->isHtml());
?>
--EXPECT--
bool(true)
bool(true)
bool(true)
bool(false)
bool(true)
bool(false)

View file

@ -1786,11 +1786,14 @@ static TIDY_NODE_METHOD(isHtml)
{ {
TIDY_FETCH_ONLY_OBJECT; TIDY_FETCH_ONLY_OBJECT;
if (tidyNodeGetType(obj->node) & (TidyNode_Start | TidyNode_End | TidyNode_StartEnd)) { switch (tidyNodeGetType(obj->node)) {
RETURN_TRUE; case TidyNode_Start:
case TidyNode_End:
case TidyNode_StartEnd:
RETURN_TRUE;
default:
RETURN_FALSE;
} }
RETURN_FALSE;
} }
/* }}} */ /* }}} */