From 78ef4f749e7be502828c647f22a29fdfc91df879 Mon Sep 17 00:00:00 2001 From: Dennis Snell Date: Wed, 24 Jan 2024 03:28:27 +0000 Subject: [PATCH] HTML API: Support INPUT tags. Adds support for the following HTML elements to the HTML Processor: - INPUT Previously this element was not supported and the HTML Processor would bail when encountering one. Now, with this patch applied, it will proceed to parse the HTML document. Developed in https://github.com/WordPress/wordpress-develop/pull/5907 Discussed in https://core.trac.wordpress.org/ticket/60283 Props jonsurrell See #60283 git-svn-id: https://develop.svn.wordpress.org/trunk@57343 602fd350-edb4-49c9-b593-d223f7449a82 --- .../html-api/class-wp-html-processor.php | 28 +++++++++++++++---- .../tests/html-api/wpHtmlProcessor.php | 1 - .../html-api/wpHtmlProcessorBreadcrumbs.php | 1 - 3 files changed, 22 insertions(+), 8 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..8a3f981ae6363 100644 --- a/src/wp-includes/html-api/class-wp-html-processor.php +++ b/src/wp-includes/html-api/class-wp-html-processor.php @@ -101,18 +101,18 @@ * * - 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. - * - Lists: DD, DL, DT, LI, OL, LI. - * - Media elements: AUDIO, CANVAS, EMBED, FIGCAPTION, FIGURE, IMG, MAP, PARAM, PICTURE, SOURCE, VIDEO, TRACK. + * - 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: 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. - * - 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 * @@ -972,6 +972,23 @@ 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 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; + /* * > A start tag whose tag name is "hr" */ @@ -1024,7 +1041,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',