From e89e2a287e8079c809207bfe61daa5b6a8f839dc Mon Sep 17 00:00:00 2001 From: Jon Surrell Date: Thu, 18 Jan 2024 17:37:25 +0100 Subject: [PATCH 1/7] Implement HR tag handling --- src/wp-includes/html-api/class-wp-html-processor.php | 12 +++++++++++- tests/phpunit/tests/html-api/wpHtmlProcessor.php | 1 - .../tests/html-api/wpHtmlProcessorBreadcrumbs.php | 1 - 3 files changed, 11 insertions(+), 3 deletions(-) diff --git a/src/wp-includes/html-api/class-wp-html-processor.php b/src/wp-includes/html-api/class-wp-html-processor.php index cce26a60c5350..5f4d08207cd53 100644 --- a/src/wp-includes/html-api/class-wp-html-processor.php +++ b/src/wp-includes/html-api/class-wp-html-processor.php @@ -941,6 +941,17 @@ private function step_in_body() { $this->reconstruct_active_formatting_elements(); $this->insert_html_element( $this->state->current_token ); return true; + + /* + * > A start tag whose tag name is "hr" + */ + case '+HR': + if ( $this->state->stack_of_open_elements->has_p_in_button_scope() ) { + $this->close_a_p_element(); + } + $this->insert_html_element( $this->state->current_token ); + $this->state->frameset_ok = false; + return true; } /* @@ -977,7 +988,6 @@ private function step_in_body() { case 'FRAME': case 'FRAMESET': case 'HEAD': - case 'HR': case 'HTML': case 'IFRAME': case 'INPUT': diff --git a/tests/phpunit/tests/html-api/wpHtmlProcessor.php b/tests/phpunit/tests/html-api/wpHtmlProcessor.php index d9f1357b5c66f..d1f0767e9ce13 100644 --- a/tests/phpunit/tests/html-api/wpHtmlProcessor.php +++ b/tests/phpunit/tests/html-api/wpHtmlProcessor.php @@ -173,7 +173,6 @@ public function data_unsupported_special_in_body_tags() { 'FRAME' => array( 'FRAME' ), 'FRAMESET' => array( 'FRAMESET' ), 'HEAD' => array( 'HEAD' ), - 'HR' => array( 'HR' ), 'HTML' => array( 'HTML' ), 'IFRAME' => array( 'IFRAME' ), 'INPUT' => array( 'INPUT' ), diff --git a/tests/phpunit/tests/html-api/wpHtmlProcessorBreadcrumbs.php b/tests/phpunit/tests/html-api/wpHtmlProcessorBreadcrumbs.php index 15d38d6f70c6c..c16d38146acb3 100644 --- a/tests/phpunit/tests/html-api/wpHtmlProcessorBreadcrumbs.php +++ b/tests/phpunit/tests/html-api/wpHtmlProcessorBreadcrumbs.php @@ -175,7 +175,6 @@ public function data_unsupported_elements() { 'FRAME', 'FRAMESET', 'HEAD', - 'HR', 'HTML', 'IFRAME', 'INPUT', From 0af0984b93cda2748400883a85d0f332801fcc78 Mon Sep 17 00:00:00 2001 From: Jon Surrell Date: Thu, 18 Jan 2024 17:53:45 +0100 Subject: [PATCH 2/7] Add test for hr closing p --- .../html-api/wpHtmlProcessorSemanticRules.php | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/tests/phpunit/tests/html-api/wpHtmlProcessorSemanticRules.php b/tests/phpunit/tests/html-api/wpHtmlProcessorSemanticRules.php index c1adf9a71a3f8..798ef76386789 100644 --- a/tests/phpunit/tests/html-api/wpHtmlProcessorSemanticRules.php +++ b/tests/phpunit/tests/html-api/wpHtmlProcessorSemanticRules.php @@ -224,6 +224,22 @@ public function test_in_body_button_with_button_in_scope_as_ancestor() { $this->assertSame( array( 'HTML', 'BODY', 'BUTTON' ), $p->get_breadcrumbs(), 'Failed to produce expected DOM nesting for third button.' ); } + /** + * Verifies that HR closes an open p tag + * + * @ticket 60283 + */ + public function test_in_body_hr_element_closes_open_p_tag( $tag_name ) { + $processor = WP_HTML_Processor::create_fragment( "


" ); + + $processor->next_tag( 'HR' ); + $this->assertSame( + array( 'HTML', 'BODY', 'HR' ), + $processor->get_breadcrumbs(), + "Expected HR to be a direct child of the BODY, having closed the open P element." + ); + } + /** * Verifies that H1 through H6 elements close an open P element. * From 74703e21eb1c529256a37f818de7daeed57d86bb Mon Sep 17 00:00:00 2001 From: Jon Surrell Date: Thu, 18 Jan 2024 17:54:47 +0100 Subject: [PATCH 3/7] Fix lints --- tests/phpunit/tests/html-api/wpHtmlProcessorSemanticRules.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/phpunit/tests/html-api/wpHtmlProcessorSemanticRules.php b/tests/phpunit/tests/html-api/wpHtmlProcessorSemanticRules.php index 798ef76386789..467ea214ac7b5 100644 --- a/tests/phpunit/tests/html-api/wpHtmlProcessorSemanticRules.php +++ b/tests/phpunit/tests/html-api/wpHtmlProcessorSemanticRules.php @@ -230,13 +230,13 @@ public function test_in_body_button_with_button_in_scope_as_ancestor() { * @ticket 60283 */ public function test_in_body_hr_element_closes_open_p_tag( $tag_name ) { - $processor = WP_HTML_Processor::create_fragment( "


" ); + $processor = WP_HTML_Processor::create_fragment( '


' ); $processor->next_tag( 'HR' ); $this->assertSame( array( 'HTML', 'BODY', 'HR' ), $processor->get_breadcrumbs(), - "Expected HR to be a direct child of the BODY, having closed the open P element." + 'Expected HR to be a direct child of the BODY, having closed the open P element.' ); } From 8bbe7bdfc7f3cac4471a0995d1272c08d7564bab Mon Sep 17 00:00:00 2001 From: Jon Surrell Date: Thu, 18 Jan 2024 18:09:18 +0100 Subject: [PATCH 4/7] Remove unused $tag_name param --- tests/phpunit/tests/html-api/wpHtmlProcessorSemanticRules.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/phpunit/tests/html-api/wpHtmlProcessorSemanticRules.php b/tests/phpunit/tests/html-api/wpHtmlProcessorSemanticRules.php index 467ea214ac7b5..ba9640f2efdc7 100644 --- a/tests/phpunit/tests/html-api/wpHtmlProcessorSemanticRules.php +++ b/tests/phpunit/tests/html-api/wpHtmlProcessorSemanticRules.php @@ -229,7 +229,7 @@ public function test_in_body_button_with_button_in_scope_as_ancestor() { * * @ticket 60283 */ - public function test_in_body_hr_element_closes_open_p_tag( $tag_name ) { + public function test_in_body_hr_element_closes_open_p_tag() { $processor = WP_HTML_Processor::create_fragment( '


' ); $processor->next_tag( 'HR' ); From 59fea1f36423da60d3964fcfe28ce0b218a98052 Mon Sep 17 00:00:00 2001 From: Jon Surrell Date: Fri, 19 Jan 2024 14:16:04 +0100 Subject: [PATCH 5/7] We should push and pop --- src/wp-includes/html-api/class-wp-html-processor.php | 1 + 1 file changed, 1 insertion(+) diff --git a/src/wp-includes/html-api/class-wp-html-processor.php b/src/wp-includes/html-api/class-wp-html-processor.php index 5f4d08207cd53..c92a5a090d975 100644 --- a/src/wp-includes/html-api/class-wp-html-processor.php +++ b/src/wp-includes/html-api/class-wp-html-processor.php @@ -950,6 +950,7 @@ private function step_in_body() { $this->close_a_p_element(); } $this->insert_html_element( $this->state->current_token ); + $this->state->stack_of_open_elements->pop(); $this->state->frameset_ok = false; return true; } From 7531b403a978d34606ffa2ec23c6a99ad520beab Mon Sep 17 00:00:00 2001 From: Jon Surrell Date: Fri, 19 Jan 2024 14:30:19 +0100 Subject: [PATCH 6/7] Revert "We should push and pop" This reverts commit 59fea1f36423da60d3964fcfe28ce0b218a98052. --- src/wp-includes/html-api/class-wp-html-processor.php | 1 - 1 file changed, 1 deletion(-) diff --git a/src/wp-includes/html-api/class-wp-html-processor.php b/src/wp-includes/html-api/class-wp-html-processor.php index c92a5a090d975..5f4d08207cd53 100644 --- a/src/wp-includes/html-api/class-wp-html-processor.php +++ b/src/wp-includes/html-api/class-wp-html-processor.php @@ -950,7 +950,6 @@ private function step_in_body() { $this->close_a_p_element(); } $this->insert_html_element( $this->state->current_token ); - $this->state->stack_of_open_elements->pop(); $this->state->frameset_ok = false; return true; } From 27f35d808af4d1ea2290be6ffc5b684562c5b718 Mon Sep 17 00:00:00 2001 From: Dennis Snell Date: Fri, 19 Jan 2024 11:58:46 -0700 Subject: [PATCH 7/7] Add HR to supported elements in class docblock --- src/wp-includes/html-api/class-wp-html-processor.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/wp-includes/html-api/class-wp-html-processor.php b/src/wp-includes/html-api/class-wp-html-processor.php index 5f4d08207cd53..910c1f24f1b18 100644 --- a/src/wp-includes/html-api/class-wp-html-processor.php +++ b/src/wp-includes/html-api/class-wp-html-processor.php @@ -109,7 +109,7 @@ * - Media elements: AUDIO, CANVAS, FIGCAPTION, FIGURE, IMG, MAP, PICTURE, VIDEO. * - Paragraph: P. * - Phrasing elements: ABBR, BDI, BDO, CITE, DATA, DEL, DFN, INS, MARK, OUTPUT, Q, SAMP, SUB, SUP, TIME, VAR. - * - Sectioning elements: ARTICLE, ASIDE, NAV, SECTION. + * - Sectioning elements: ARTICLE, ASIDE, HR, NAV, SECTION. * - Templating elements: SLOT. * - Text decoration: RUBY. * - Deprecated elements: ACRONYM, BLINK, CENTER, DIR, ISINDEX, MULTICOL, NEXTID, SPACER.