From fcf8b09dd720b968db979ac3eabf104e1369b9d9 Mon Sep 17 00:00:00 2001 From: Jon Surrell Date: Fri, 19 Jan 2024 14:30:03 +0100 Subject: [PATCH 1/7] Add INPUT tag handling --- .../html-api/class-wp-html-processor.php | 13 ++++++++++++- tests/phpunit/tests/html-api/wpHtmlProcessor.php | 1 - .../tests/html-api/wpHtmlProcessorBreadcrumbs.php | 1 - 3 files changed, 12 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 f0c3b27b284e2..ebd28a3a6f001 100644 --- a/src/wp-includes/html-api/class-wp-html-processor.php +++ b/src/wp-includes/html-api/class-wp-html-processor.php @@ -972,6 +972,18 @@ private function step_in_body() { $this->state->frameset_ok = false; return true; + /* + * > A start tag whose tag name is "input" + */ + case '+INPUT': + $this->reconstruct_active_formatting_elements(); + $this->insert_html_element( $this->state->current_token ); + $type_attribute = $this->get_attribute( 'type' ); + if ( null === $type_attribute || 'hidden' === strtolower( $type_attribute ) ) { + $this->state->frameset_ok = false; + } + return true; + /* * > A start tag whose tag name is "hr" */ @@ -1024,7 +1036,6 @@ private function step_in_body() { case 'HEAD': case 'HTML': case 'IFRAME': - case 'INPUT': case 'LINK': case 'MARQUEE': case 'MATH': diff --git a/tests/phpunit/tests/html-api/wpHtmlProcessor.php b/tests/phpunit/tests/html-api/wpHtmlProcessor.php index 232fecebf8927..109f384e25e3c 100644 --- a/tests/phpunit/tests/html-api/wpHtmlProcessor.php +++ b/tests/phpunit/tests/html-api/wpHtmlProcessor.php @@ -253,7 +253,6 @@ public function data_unsupported_special_in_body_tags() { 'HEAD' => array( 'HEAD' ), 'HTML' => array( 'HTML' ), 'IFRAME' => array( 'IFRAME' ), - 'INPUT' => array( 'INPUT' ), 'LINK' => array( 'LINK' ), 'MARQUEE' => array( 'MARQUEE' ), 'MATH' => array( 'MATH' ), diff --git a/tests/phpunit/tests/html-api/wpHtmlProcessorBreadcrumbs.php b/tests/phpunit/tests/html-api/wpHtmlProcessorBreadcrumbs.php index b9d567fbebed6..af3df4a3e6f99 100644 --- a/tests/phpunit/tests/html-api/wpHtmlProcessorBreadcrumbs.php +++ b/tests/phpunit/tests/html-api/wpHtmlProcessorBreadcrumbs.php @@ -180,7 +180,6 @@ public function data_unsupported_elements() { 'HEAD', 'HTML', 'IFRAME', - 'INPUT', 'LINK', 'MARQUEE', // Deprecated. 'MATH', From eda7f44c35c52dccf8bdb1d1ece9eff1e46028ae Mon Sep 17 00:00:00 2001 From: Jon Surrell Date: Tue, 23 Jan 2024 12:16:19 +0100 Subject: [PATCH 2/7] Add INPUT to supported elements doc --- 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 ebd28a3a6f001..d91704414a97b 100644 --- a/src/wp-includes/html-api/class-wp-html-processor.php +++ b/src/wp-includes/html-api/class-wp-html-processor.php @@ -101,7 +101,7 @@ * * - Containers: ADDRESS, BLOCKQUOTE, DETAILS, DIALOG, DIV, FOOTER, HEADER, MAIN, MENU, SPAN, SUMMARY. * - Custom elements: All custom elements are supported. :) - * - Form elements: BUTTON, DATALIST, FIELDSET, LABEL, LEGEND, METER, PROGRESS, SEARCH. + * - Form elements: BUTTON, DATALIST, FIELDSET, INPUT, LABEL, LEGEND, METER, PROGRESS, SEARCH. * - Formatting elements: B, BIG, CODE, EM, FONT, I, PRE, SMALL, STRIKE, STRONG, TT, U, WBR. * - Heading elements: H1, H2, H3, H4, H5, H6, HGROUP. * - Links: A. From 75af05420cc6c53cd69ced26ead2ee7261e01bf6 Mon Sep 17 00:00:00 2001 From: Jon Surrell Date: Tue, 23 Jan 2024 12:16:57 +0100 Subject: [PATCH 3/7] Move PARAM to supported deprecated elements --- src/wp-includes/html-api/class-wp-html-processor.php | 4 ++-- 1 file changed, 2 insertions(+), 2 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 d91704414a97b..a05acf2940d64 100644 --- a/src/wp-includes/html-api/class-wp-html-processor.php +++ b/src/wp-includes/html-api/class-wp-html-processor.php @@ -106,13 +106,13 @@ * - Heading elements: H1, H2, H3, H4, H5, H6, HGROUP. * - Links: A. * - Lists: DD, DL, DT, LI, OL, LI. - * - Media elements: AUDIO, CANVAS, EMBED, FIGCAPTION, FIGURE, IMG, MAP, PARAM, PICTURE, SOURCE, VIDEO, TRACK. + * - Media elements: AUDIO, CANVAS, EMBED, FIGCAPTION, FIGURE, IMG, MAP, PICTURE, SOURCE, VIDEO, TRACK. * - Paragraph: BR, P. * - Phrasing elements: AREA, ABBR, BDI, BDO, CITE, DATA, DEL, DFN, INS, MARK, OUTPUT, Q, SAMP, SUB, SUP, TIME, VAR. * - Sectioning elements: ARTICLE, ASIDE, HR, NAV, SECTION. * - Templating elements: SLOT. * - Text decoration: RUBY. - * - Deprecated elements: ACRONYM, BLINK, CENTER, DIR, ISINDEX, KEYGEN, LISTING, MULTICOL, NEXTID, SPACER. + * - Deprecated elements: ACRONYM, BLINK, CENTER, DIR, ISINDEX, KEYGEN, LISTING, MULTICOL, NEXTID, PARAM, SPACER. * * ### Supported markup * From 7d273ddf418a5d4d7df3fc91099d0c76ff3c18d0 Mon Sep 17 00:00:00 2001 From: Jon Surrell Date: Tue, 23 Jan 2024 12:19:03 +0100 Subject: [PATCH 4/7] Alphabetize supported elements lists --- src/wp-includes/html-api/class-wp-html-processor.php | 4 ++-- 1 file changed, 2 insertions(+), 2 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 a05acf2940d64..5b571aaea071b 100644 --- a/src/wp-includes/html-api/class-wp-html-processor.php +++ b/src/wp-includes/html-api/class-wp-html-processor.php @@ -106,9 +106,9 @@ * - Heading elements: H1, H2, H3, H4, H5, H6, HGROUP. * - Links: A. * - Lists: DD, DL, DT, LI, OL, LI. - * - Media elements: AUDIO, CANVAS, EMBED, FIGCAPTION, FIGURE, IMG, MAP, PICTURE, SOURCE, VIDEO, TRACK. + * - Media elements: AUDIO, CANVAS, EMBED, FIGCAPTION, FIGURE, IMG, MAP, PICTURE, SOURCE, TRACK, VIDEO. * - Paragraph: BR, P. - * - Phrasing elements: AREA, ABBR, BDI, BDO, CITE, DATA, DEL, DFN, INS, MARK, OUTPUT, Q, SAMP, SUB, SUP, TIME, VAR. + * - Phrasing elements: ABBR, AREA, BDI, BDO, CITE, DATA, DEL, DFN, INS, MARK, OUTPUT, Q, SAMP, SUB, SUP, TIME, VAR. * - Sectioning elements: ARTICLE, ASIDE, HR, NAV, SECTION. * - Templating elements: SLOT. * - Text decoration: RUBY. From c651133cfc02033930b1306125e7d0fec22db51f Mon Sep 17 00:00:00 2001 From: Jon Surrell Date: Tue, 23 Jan 2024 12:20:27 +0100 Subject: [PATCH 5/7] Fix repeated LI supported element (UL) See https://github.com/WordPress/wordpress-develop/pull/5539#discussion_r1452955863 --- 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 5b571aaea071b..13a172c1c7865 100644 --- a/src/wp-includes/html-api/class-wp-html-processor.php +++ b/src/wp-includes/html-api/class-wp-html-processor.php @@ -105,7 +105,7 @@ * - Formatting elements: B, BIG, CODE, EM, FONT, I, PRE, SMALL, STRIKE, STRONG, TT, U, WBR. * - Heading elements: H1, H2, H3, H4, H5, H6, HGROUP. * - Links: A. - * - Lists: DD, DL, DT, LI, OL, LI. + * - Lists: DD, DL, DT, LI, OL, UL. * - Media elements: AUDIO, CANVAS, EMBED, FIGCAPTION, FIGURE, IMG, MAP, PICTURE, SOURCE, TRACK, VIDEO. * - Paragraph: BR, P. * - Phrasing elements: ABBR, AREA, BDI, BDO, CITE, DATA, DEL, DFN, INS, MARK, OUTPUT, Q, SAMP, SUB, SUP, TIME, VAR. From 60a1af791606ab256b90f78a1fcc48039cf6170d Mon Sep 17 00:00:00 2001 From: Jon Surrell Date: Tue, 23 Jan 2024 12:28:44 +0100 Subject: [PATCH 6/7] Fix frameset checking and logic --- src/wp-includes/html-api/class-wp-html-processor.php | 10 +++++++++- 1 file changed, 9 insertions(+), 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 13a172c1c7865..d2a2caf37ef29 100644 --- a/src/wp-includes/html-api/class-wp-html-processor.php +++ b/src/wp-includes/html-api/class-wp-html-processor.php @@ -976,10 +976,18 @@ private function step_in_body() { * > A start tag whose tag name is "input" */ case '+INPUT': + + + $this->reconstruct_active_formatting_elements(); $this->insert_html_element( $this->state->current_token ); $type_attribute = $this->get_attribute( 'type' ); - if ( null === $type_attribute || 'hidden' === strtolower( $type_attribute ) ) { + /* + * > If the token does not have an attribute with the name "type", or if it does, + * > but that attribute's value is not an ASCII case-insensitive match for the + * > string "hidden", then: set the frameset-ok flag to "not ok". + */ + if ( ! is_string( $type_attribute ) || 'hidden' !== strtolower( $type_attribute ) ) { $this->state->frameset_ok = false; } return true; From fee724fbf386c4837885b1d74e10e3dfa2ad30d9 Mon Sep 17 00:00:00 2001 From: Jon Surrell Date: Tue, 23 Jan 2024 12:33:49 +0100 Subject: [PATCH 7/7] Remove redundant spaces in case --- src/wp-includes/html-api/class-wp-html-processor.php | 3 --- 1 file changed, 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 d2a2caf37ef29..8a3f981ae6363 100644 --- a/src/wp-includes/html-api/class-wp-html-processor.php +++ b/src/wp-includes/html-api/class-wp-html-processor.php @@ -976,9 +976,6 @@ private function step_in_body() { * > A start tag whose tag name is "input" */ case '+INPUT': - - - $this->reconstruct_active_formatting_elements(); $this->insert_html_element( $this->state->current_token ); $type_attribute = $this->get_attribute( 'type' );