Skip to content

Commit aa485ba

Browse files
committed
Add support for "any other tag" categories in IN BODY
1 parent 1e9be91 commit aa485ba

3 files changed

Lines changed: 47 additions & 20 deletions

File tree

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

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -879,6 +879,8 @@ private function step_in_body() {
879879
* @see https://html.spec.whatwg.org/multipage/parsing.html#parsing-main-inbody
880880
*/
881881
switch ( $tag_name ) {
882+
case 'ABBR':
883+
case 'ACRONYM':
882884
case 'APPLET':
883885
case 'AREA':
884886
case 'BASE':
@@ -945,6 +947,47 @@ private function step_in_body() {
945947
throw new WP_HTML_Unsupported_Exception( "Cannot process {$tag_name} element." );
946948
}
947949

950+
if ( ! $this->is_tag_closer() ) {
951+
// > Any other start tag.
952+
$this->reconstruct_active_formatting_elements();
953+
$this->insert_html_element( $this->state->current_token );
954+
return true;
955+
} else {
956+
// > Any other end tag
957+
$node = $this->state->stack_of_open_elements->current_node();
958+
959+
in_body_any_other_end_tag_loop:
960+
if ( $tag_name === $node->node_name ) {
961+
$this->generate_implied_end_tags( $tag_name );
962+
if ( $node !== $this->state->stack_of_open_elements->current_node() ) {
963+
// @todo Record parse error: this error doesn't impact parsing.
964+
}
965+
$pop_count = 0;
966+
foreach ( $this->state->stack_of_open_elements->walk_up() as $item ) {
967+
++$pop_count;
968+
if ( $node === $item ) {
969+
break;
970+
}
971+
}
972+
while ( $pop_count-- > 0 ) {
973+
$this->state->stack_of_open_elements->pop();
974+
}
975+
return true;
976+
} elseif ( self::is_special( $node->node_name ) ) {
977+
// This is a parse error, ignore the token.
978+
return $this->step();
979+
}
980+
$one_shot = false;
981+
foreach ( $this->state->stack_of_open_elements->walk_up() as $item ) {
982+
if ( $one_shot ) {
983+
$node = $item;
984+
goto in_body_any_other_end_tag_loop;
985+
}
986+
987+
$one_shot = true;
988+
}
989+
}
990+
948991
$this->last_error = self::ERROR_UNSUPPORTED;
949992
throw new WP_HTML_Unsupported_Exception( "Cannot process {$tag_name} element." );
950993
}

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

Lines changed: 0 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -60,22 +60,6 @@ public function test_get_tag_is_null_once_document_is_finished() {
6060
$this->assertNull( $p->get_tag() );
6161
}
6262

63-
/**
64-
* Ensures that if the HTML Processor encounters inputs that it can't properly handle,
65-
* that it stops processing the rest of the document. This prevents data corruption.
66-
*
67-
* @ticket 59167
68-
*
69-
* @covers WP_HTML_Processor::next_tag
70-
*/
71-
public function test_stops_processing_after_unsupported_elements() {
72-
$p = WP_HTML_Processor::create_fragment( '<p><x-not-supported></p><p></p>' );
73-
$p->next_tag( 'P' );
74-
$this->assertFalse( $p->next_tag(), 'Stepped into a tag after encountering X-NOT-SUPPORTED element when it should have aborted.' );
75-
$this->assertNull( $p->get_tag(), "Should have aborted processing, but still reported tag {$p->get_tag()} after properly failing to step into tag." );
76-
$this->assertFalse( $p->next_tag( 'P' ), 'Stepped into normal P element after X-NOT-SUPPORTED element when it should have aborted.' );
77-
}
78-
7963
/**
8064
* Ensures that the HTML Processor maintains its internal state through seek calls.
8165
*

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

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -216,10 +216,6 @@ public function data_unsupported_elements() {
216216
'VIDEO',
217217
'WBR',
218218
'XMP', // Deprecated, use PRE instead.
219-
220-
// Made up elements, custom elements.
221-
'X-NOT-AN-HTML-ELEMENT',
222-
'HUMAN-TIME',
223219
);
224220

225221
$data = array();
@@ -360,6 +356,10 @@ public function data_html_target_with_breadcrumbs() {
360356
'H4 inside H2' => array( '<h2><span>Major<h4 target>Minor</h3></span>', array( 'HTML', 'BODY', 'H2', 'SPAN', 'H4' ), 1 ),
361357
'H5 after unclosed H4 inside H2' => array( '<h2><span>Major<h4>Minor</span></h3><h5 target>', array( 'HTML', 'BODY', 'H2', 'SPAN', 'H5' ), 1 ),
362358
'H5 after H4 inside H2' => array( '<h2><span>Major<h4>Minor</h4></span></h3><h5 target>', array( 'HTML', 'BODY', 'H5' ), 1 ),
359+
360+
// Custom elements.
361+
'WP-EMOJI' => array( '<div><wp-emoji target></wp-emoji></div>', array( 'HTML', 'BODY', 'DIV', 'WP-EMOJI' ), 1 ),
362+
'WP-EMOJI then IMG' => array( '<div><wp-emoji></wp-emoji><img target></div>', array( 'HTML', 'BODY', 'DIV', 'IMG' ), 1 ),
363363
);
364364
}
365365

0 commit comments

Comments
 (0)