Skip to content

Commit da5f9d9

Browse files
committed
Review all failing tests, add some test fixes, add some fixes
1 parent 1f2e6fb commit da5f9d9

File tree

2 files changed

+12
-4
lines changed

2 files changed

+12
-4
lines changed

src/wp-includes/html-api/class-wp-html-tag-processor.php

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1268,6 +1268,8 @@ private function skip_script_data() {
12681268
}
12691269

12701270
if ( $this->bytes_already_parsed >= $doc_length ) {
1271+
$this->parser_state = self::STATE_INCOMPLETE;
1272+
12711273
return false;
12721274
}
12731275

@@ -1316,7 +1318,7 @@ private function parse_next_tag() {
13161318

13171319
$this->token_starts_at = $at;
13181320

1319-
if ( $at + 1 < $doc_length && '/' === $this->html[ $at + 1 ] ) {
1321+
if ( $doc_length > $at + 1 && '/' === $this->html[ $at + 1 ] ) {
13201322
$this->is_closing_tag = true;
13211323
++$at;
13221324
} else {
@@ -1366,7 +1368,7 @@ private function parse_next_tag() {
13661368
* https://html.spec.whatwg.org/multipage/parsing.html#tag-open-state
13671369
*/
13681370
if (
1369-
strlen( $html ) > $at + 3 &&
1371+
$doc_length > $at + 3 &&
13701372
'-' === $html[ $at + 2 ] &&
13711373
'-' === $html[ $at + 3 ]
13721374
) {
@@ -1516,7 +1518,7 @@ private function parse_next_tag() {
15161518
* See https://html.spec.whatwg.org/#parse-error-invalid-first-character-of-tag-name
15171519
*/
15181520
if ( $this->is_closing_tag ) {
1519-
// No chance of finding a closer.
1521+
// No chance of finding a closer
15201522
if ( $at + 3 > $doc_length ) {
15211523
return false;
15221524
}

tests/phpunit/tests/html-api/wpHtmlProcessorHtml5lib.php

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,10 +20,13 @@ class Tests_HtmlApi_WpHtmlProcessorHtml5lib extends WP_UnitTestCase {
2020
'adoption01/case4 - line 46' => 'Unimplemented: Reconstruction of active formatting elements.',
2121
'tests15/case1 - line 1' => 'Unimplemented: Reconstruction of active formatting elements.',
2222
'tests15/case2 - line 22' => 'Unimplemented: Reconstruction of active formatting elements.',
23+
'tests20/case38 - line 483' => 'XMP is a special token an needs a closer.',
24+
'tests20/case39 - line 497' => "Closing P tag implicitly creates opener, which we don't visit.",
2325
'tests23/case1 - line 1' => 'Unimplemented: Reconstruction of active formatting elements.',
2426
'tests23/case2 - line 41' => 'Unimplemented: Reconstruction of active formatting elements.',
2527
'tests23/case3 - line 69' => 'Unimplemented: Reconstruction of active formatting elements.',
2628
'tests23/case4 - line 101' => 'Unimplemented: Reconstruction of active formatting elements.',
29+
'tests26/case10 - line 263' => 'Newline at end of tag triggers reconstruction of active formatting elements.',
2730
);
2831

2932
/**
@@ -111,7 +114,10 @@ public static function build_html5_treelike_string( $fragment_context, $html ) {
111114
$output .= "<{$t}>\n";
112115
}
113116

114-
if ( WP_HTML_Processor::ERROR_UNSUPPORTED === $p->get_last_error() ) {
117+
if (
118+
$p->paused_at_incomplete_token() ||
119+
WP_HTML_Processor::ERROR_UNSUPPORTED === $p->get_last_error()
120+
) {
115121
return null;
116122
}
117123

0 commit comments

Comments
 (0)