Skip to content

Commit e68acd0

Browse files
committed
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.
1 parent e857dfa commit e68acd0

File tree

3 files changed

+37
-4
lines changed

3 files changed

+37
-4
lines changed

NEWS

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,9 @@ PHP NEWS
3535
. Fixed bug #76943 (Inconsistent stream_wrapper_restore() errors). (cmb)
3636
. Fixed bug #76735 (Incorrect message in fopen on invalid mode). (cmb)
3737

38+
- Tidy:
39+
. Fixed bug #77040 (tidyNode::isHtml() is completely broken). (cmb)
40+
3841
01 Oct 2020, PHP 7.3.23
3942

4043
- Core:

ext/tidy/tests/bug77040.phpt

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
--TEST--
2+
Bug #77040 (tidyNode::isHtml() is completely broken)
3+
--SKIPIF--
4+
<?php
5+
if (!extension_loaded('tidy')) die('skip tidy extension not available');
6+
?>
7+
--FILE--
8+
<?php
9+
$tidy = new tidy;
10+
$tidy->parseString("<p>text</p><p><![CDATA[cdata]]></p>");
11+
$p = $tidy->body()->child[0];
12+
var_dump($p->type === TIDY_NODETYPE_START);
13+
var_dump($p->isHtml());
14+
$text = $p->child[0];
15+
var_dump($text->type === TIDY_NODETYPE_TEXT);
16+
var_dump($text->isHtml());
17+
$cdata = $tidy->body()->child[1]->child[0];
18+
var_dump($cdata->type === TIDY_NODETYPE_CDATA);
19+
var_dump($cdata->isHtml());
20+
?>
21+
--EXPECT--
22+
bool(true)
23+
bool(true)
24+
bool(true)
25+
bool(false)
26+
bool(true)
27+
bool(false)

ext/tidy/tidy.c

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1786,11 +1786,14 @@ static TIDY_NODE_METHOD(isHtml)
17861786
{
17871787
TIDY_FETCH_ONLY_OBJECT;
17881788

1789-
if (tidyNodeGetType(obj->node) & (TidyNode_Start | TidyNode_End | TidyNode_StartEnd)) {
1790-
RETURN_TRUE;
1789+
switch (tidyNodeGetType(obj->node)) {
1790+
case TidyNode_Start:
1791+
case TidyNode_End:
1792+
case TidyNode_StartEnd:
1793+
RETURN_TRUE;
1794+
default:
1795+
RETURN_FALSE;
17911796
}
1792-
1793-
RETURN_FALSE;
17941797
}
17951798
/* }}} */
17961799

0 commit comments

Comments
 (0)