Make WordPress Core

Changeset 57316

Timestamp:
01/19/2024 09:40:01 PM (6 months ago)
Author:
dmsnell
Message:

HTML API: Add support for BR, EMBED, & other tags.

Adds support for the following HTML elements to the HTML Processor:

  • AREA, BR, EMBED, KEYGEN, WBR
  • Only the opening BR tag is supported, as the invalid closer </br> involves more complicated rules, to be implemented later.

Previously, these elements were not supported and the HTML Processor
would bail when encountering them. With this patch it will proceed to
parse an HTML document when encountering those tags as long as other
normal conditions don't cause it to bail (such as complicated format
reconstruction rules).

Props jonsurrell, dmsnell
Fixes #60283

Location:
trunk
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/wp-includes/html-api/class-wp-html-processor.php

    r57314 r57316  
    103103 *  - Custom elements: All custom elements are supported. :)
    104104 *  - Form elements: BUTTON, DATALIST, FIELDSET, LABEL, LEGEND, METER, PROGRESS, SEARCH.
    105  *  - Formatting elements: B, BIG, CODE, EM, FONT, I, SMALL, STRIKE, STRONG, TT, U.
     105 *  - Formatting elements: B, BIG, CODE, EM, FONT, I, SMALL, STRIKE, STRONG, TT, U.
    106106 *  - Heading elements: H1, H2, H3, H4, H5, H6, HGROUP.
    107107 *  - Links: A.
    108108 *  - Lists: DD, DL, DT, LI, OL, LI.
    109  *  - Media elements: AUDIO, CANVAS, FIGCAPTION, FIGURE, IMG, MAP, PICTURE, VIDEO.
    110  *  - Paragraph: P.
    111  *  - Phrasing elements: ABBR, BDI, BDO, CITE, DATA, DEL, DFN, INS, MARK, OUTPUT, Q, SAMP, SUB, SUP, TIME, VAR.
     109 *  - Media elements: AUDIO, CANVAS, FIGCAPTION, FIGURE, IMG, MAP, PICTURE, VIDEO.
     110 *  - Paragraph: P.
     111 *  - Phrasing elements: ABBR, BDI, BDO, CITE, DATA, DEL, DFN, INS, MARK, OUTPUT, Q, SAMP, SUB, SUP, TIME, VAR.
    112112 *  - Sectioning elements: ARTICLE, ASIDE, HR, NAV, SECTION.
    113113 *  - Templating elements: SLOT.
    114114 *  - Text decoration: RUBY.
    115  *  - Deprecated elements: ACRONYM, BLINK, CENTER, DIR, ISINDEX, MULTICOL, NEXTID, SPACER.
     115 *  - Deprecated elements: ACRONYM, BLINK, CENTER, DIR, ISINDEX, MULTICOL, NEXTID, SPACER.
    116116 *
    117117 * ### Supported markup
     
    936936
    937937            /*
     938
     939
     940
     941
     942
     943
     944
     945
     946
     947
    938948             * > A start tag whose tag name is one of: "area", "br", "embed", "img", "keygen", "wbr"
    939949             */
     950
     951
     952
    940953            case '+IMG':
     954
     955
    941956                $this->reconstruct_active_formatting_elements();
    942957                $this->insert_html_element( $this->state->current_token );
     958
    943959                return true;
    944960
     
    978994            case 'BGSOUND':
    979995            case 'BODY':
    980             case 'BR':
    981996            case 'CAPTION':
    982997            case 'COL':
     
    984999            case 'DD':
    9851000            case 'DT':
    986             case 'EMBED':
    9871001            case 'FORM':
    9881002            case 'FRAME':
     
    9921006            case 'IFRAME':
    9931007            case 'INPUT':
    994             case 'KEYGEN':
    9951008            case 'LI':
    9961009            case 'LINK':
     
    10321045            case 'TRACK':
    10331046            case 'UL':
    1034             case 'WBR':
    10351047            case 'XMP':
    10361048                $this->last_error = self::ERROR_UNSUPPORTED;
     
    16931705            'INPUT' === $tag_name ||
    16941706            'LINK' === $tag_name ||
     1707
    16951708            'META' === $tag_name ||
    16961709            'SOURCE' === $tag_name ||
  • trunk/tests/phpunit/tests/html-api/wpHtmlProcessor.php

    r57314 r57316  
    134134
    135135    /**
     136
     137
     138
     139
     140
     141
     142
     143
     144
     145
     146
     147
     148
     149
     150
     151
     152
     153
     154
     155
     156
     157
     158
     159
     160
     161
     162
     163
     164
     165
     166
     167
     168
     169
     170
     171
     172
     173
     174
     175
     176
     177
     178
     179
     180
     181
     182
     183
     184
     185
     186
     187
     188
     189
     190
     191
     192
     193
     194
     195
     196
     197
     198
     199
     200
     201
     202
     203
     204
     205
     206
     207
     208
     209
     210
     211
     212
     213
     214
     215
    136216     * Ensures that special handling of unsupported tags is cleaned up
    137217     * as handling is implemented. Otherwise there's risk of leaving special
     
    160240        return array(
    161241            'APPLET'    => array( 'APPLET' ),
    162             'AREA'      => array( 'AREA' ),
    163242            'BASE'      => array( 'BASE' ),
    164243            'BASEFONT'  => array( 'BASEFONT' ),
    165244            'BGSOUND'   => array( 'BGSOUND' ),
    166245            'BODY'      => array( 'BODY' ),
    167             'BR'        => array( 'BR' ),
    168246            'CAPTION'   => array( 'CAPTION' ),
    169247            'COL'       => array( 'COL' ),
    170248            'COLGROUP'  => array( 'COLGROUP' ),
    171             'EMBED'     => array( 'EMBED' ),
    172249            'FORM'      => array( 'FORM' ),
    173250            'FRAME'     => array( 'FRAME' ),
     
    177254            'IFRAME'    => array( 'IFRAME' ),
    178255            'INPUT'     => array( 'INPUT' ),
    179             'KEYGEN'    => array( 'KEYGEN' ),
    180256            'LINK'      => array( 'LINK' ),
    181257            'LISTING'   => array( 'LISTING' ),
     
    214290            'TR'        => array( 'TR' ),
    215291            'TRACK'     => array( 'TRACK' ),
    216             'WBR'       => array( 'WBR' ),
    217292            'XMP'       => array( 'XMP' ),
    218293        );
  • trunk/tests/phpunit/tests/html-api/wpHtmlProcessorBreadcrumbs.php

    r57314 r57316  
    163163        $unsupported_elements = array(
    164164            'APPLET', // Deprecated.
    165             'AREA',
    166165            'BASE',
    167166            'BGSOUND', // Deprecated; self-closing if self-closing flag provided, otherwise normal.
    168167            'BODY',
    169             'BR',
    170168            'CAPTION',
    171169            'COL',
    172170            'COLGROUP',
    173             'EMBED',
    174171            'FORM',
    175172            'FRAME',
     
    179176            'IFRAME',
    180177            'INPUT',
    181             'KEYGEN', // Deprecated; void.
    182178            'LINK',
    183179            'LISTING', // Deprecated, use PRE instead.
     
    214210            'TR',
    215211            'TRACK',
    216             'WBR',
    217212            'XMP', // Deprecated, use PRE instead.
    218213        );
  • trunk/tests/phpunit/tests/html-api/wpHtmlProcessorSemanticRules.php

    r57314 r57316  
    393393        $this->assertSame( array( 'HTML', 'BODY', 'DIV', 'DIV' ), $p->get_breadcrumbs(), 'Failed to produce expected DOM nesting: SPAN should be closed and DIV should be its sibling.' );
    394394    }
     395
     396
     397
     398
     399
     400
     401
     402
     403
     404
     405
     406
     407
     408
     409
     410
     411
     412
     413
     414
     415
     416
     417
     418
     419
    395420}
Note: See TracChangeset for help on using the changeset viewer.