Make WordPress Core


Ignore:
Timestamp:
06/23/2020 05:05:57 AM (6 years ago)
Author:
whyisjake
Message:

Formatting: Extend wp_kses_hair and wp_kses_hair_parse to allow digits and underscores.

Fixes a lot of issues around parsing XML/HTML attributes.

Fixes #49464.

See #34406, #48608.

Props codeforest, zodiac1978, johnpgreen, dlh, ayeshrajans, johnpgreen, rilwis, travisnorthcutt, miqrogroove, chriscct7, whyisjake.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/wp-includes/kses.php

    r48121 r48132  
    12621262                switch ( $mode ) {
    12631263                        case 0:
    1264                                 if ( preg_match( '/^([-a-zA-Z:]+)/', $attr, $match ) ) {
     1264                                if ( preg_match( '/^([_a-zA-Z][-_a-zA-Z0-9:.]*)/', $attr, $match ) ) {
    12651265                                        $attrname = $match[1];
    12661266                                        $working  = 1;
    12671267                                        $mode     = 1;
    1268                                         $attr     = preg_replace( '/^[-a-zA-Z:]+/', '', $attr );
     1268                                        $attr     = preg_replace( '/^[_a-zA-Z][-_a-zA-Z0-9:.]*/', '', $attr );
    12691269                                }
    12701270
     
    14521452        // phpcs:disable Squiz.Strings.ConcatenationSpacing.PaddingFound -- don't remove regex indentation
    14531453        $regex =
    1454         '(?:'
    1455         .     '[-a-zA-Z:]+'   // Attribute name.
    1456         . '|'
    1457         .     '\[\[?[^\[\]]+\]\]?' // Shortcode in the name position implies unfiltered_html.
    1458         . ')'
    1459         . '(?:'               // Attribute value.
    1460         .     '\s*=\s*'       // All values begin with '='.
    1461         .     '(?:'
    1462         .         '"[^"]*"'   // Double-quoted.
    1463         .     '|'
    1464         .         "'[^']*'"   // Single-quoted.
    1465         .     '|'
    1466         .         '[^\s"\']+' // Non-quoted.
    1467         .         '(?:\s|$)'  // Must have a space.
    1468         .     ')'
    1469         . '|'
    1470         .     '(?:\s|$)'      // If attribute has no value, space is required.
    1471         . ')'
    1472         . '\s*';              // Trailing space is optional except as mentioned above.
     1454                '(?:'
     1455                .     '[_a-zA-Z][-_a-zA-Z0-9:.]*'   // Attribute name.
     1456                . '|'
     1457                .     '\[\[?[^\[\]]+\]\]?' // Shortcode in the name position implies unfiltered_html.
     1458                . ')'
     1459                . '(?:'               // Attribute value.
     1460                .     '\s*=\s*'       // All values begin with '='.
     1461                .     '(?:'
     1462                .         '"[^"]*"'   // Double-quoted.
     1463                .     '|'
     1464                .         "'[^']*'"   // Single-quoted.
     1465                .     '|'
     1466                .         '[^\s"\']+' // Non-quoted.
     1467                .         '(?:\s|$)'  // Must have a space.
     1468                .     ')'
     1469                . '|'
     1470                .     '(?:\s|$)'      // If attribute has no value, space is required.
     1471                . ')'
     1472                . '\s*';              // Trailing space is optional except as mentioned above.
    14731473        // phpcs:enable
    14741474
Note: See TracChangeset for help on using the changeset viewer.