Make WordPress Core

Changeset 45989


Ignore:
Timestamp:
09/04/2019 05:22:29 PM (5 years ago)
Author:
whyisjake
Message:

Update wp.a11y.speak() to sanitize HTML before display.

Merges [45979] to the 5.2 branch

Props iandunn, adamsilverstein, sstoqnov, peterwilsoncc

Location:
branches/5.2
Files:
9 edited

Legend:

Unmodified
Added
Removed
  • branches/5.2

  • branches/5.2/src/js/_enqueues/admin/post.js

    r44896 r45989  
    796796
    797797            // Update "Status:" to currently selected status.
    798             $('#post-status-display').html($('option:selected', postStatus).text());
     798            $('#post-status-display').text(
     799                wp.sanitize.stripTagsAndEncodeText( $('option:selected', postStatus).text() ) // Remove any potential tags from post status text.
     800            );
    799801
    800802            // Show or hide the "Save Draft" button.
  • branches/5.2/src/js/_enqueues/wp/a11y.js

    r43347 r45989  
    2828        clear();
    2929
    30         // Ensure only text is sent to screen readers.
    31         message = $( '<p>' ).html( message ).text();
     30        // Remove HTML tags, ensuring only text is sent to screen readers.
     31        message = wp.sanitize.stripTagsAndEncodeText( message );
    3232
    3333        /*
  • branches/5.2/src/js/_enqueues/wp/customize/nav-menus.js

    r45870 r45989  
    34573457    function displayNavMenuName( name ) {
    34583458        name = name || '';
    3459         name = $( '<div>' ).text( name ).html(); // Emulate esc_html() which is used in wp-admin/nav-menus.php.
     3459        name = wp.sanitize.stripTagsAndEncodeText( name ); // Remove any potential tags from name.
    34603460        name = $.trim( name );
    34613461        return name || api.Menus.data.l10n.unnamed;
  • branches/5.2/src/js/_enqueues/wp/sanitize.js

    r43347 r45989  
    2424            text = text || '';
    2525
    26             return text
    27                 .replace( /<!--[\s\S]*?(-->|$)/g, '' )
    28                 .replace( /<(script|style)[^>]*>[\s\S]*?(<\/\1>|$)/ig, '' )
    29                 .replace( /<\/?[a-z][\s\S]*?(>|$)/ig, '' );
     26            // Do the replacement.
     27            var _text = text
     28                    .replace( /<!--[\s\S]*?(-->|$)/g, '' )
     29                    .replace( /<(script|style)[^>]*>[\s\S]*?(<\/\1>|$)/ig, '' )
     30                    .replace( /<\/?[a-z][\s\S]*?(>|$)/ig, '' );
     31
     32            // If the initial text is not equal to the modified text,
     33            // do the search-replace again, until there is nothing to be replaced.
     34            if ( _text !== text ) {
     35                return wp.sanitize.stripTags( _text );
     36            }
     37
     38            // Return the text with stripped tags.
     39            return _text;
    3040        },
    3141
     
    4252
    4353            try {
    44                 textarea.innerHTML = _text;
     54                textarea.textContent = _text;
    4555                _text = wp.sanitize.stripTags( textarea.value );
    4656            } catch ( er ) {}
  • branches/5.2/src/js/_enqueues/wp/updates.js

    r44417 r45989  
    263263        if ( 'undefined' !== typeof response.debug && window.console && window.console.log ) {
    264264            _.map( response.debug, function( message ) {
    265                 window.console.log( $( '<p />' ).html( message ).text() );
     265                // Remove all HTML tags and write a message to the console.
     266                window.console.log( wp.sanitize.stripTagsAndEncodeText( message ) );
    266267            } );
    267268        }
  • branches/5.2/src/wp-includes/script-loader.php

    r45844 r45989  
    880880    );
    881881
    882     $scripts->add( 'wp-a11y', "/wp-includes/js/wp-a11y$suffix.js", array( 'jquery' ), false, 1 );
     882    $scripts->add( 'wp-sanitize', "/wp-includes/js/wp-sanitize$suffix.js", array(), false, 1 );
     883
     884    $scripts->add( 'wp-a11y', "/wp-includes/js/wp-a11y$suffix.js", array( 'jquery', 'wp-sanitize' ), false, 1 );
    883885
    884886    $scripts->add( 'sack', "/wp-includes/js/tw-sack$suffix.js", array(), '1.6.1', 1 );
     
    14831485    $scripts->add( 'customize-preview-widgets', "/wp-includes/js/customize-preview-widgets$suffix.js", array( 'jquery', 'wp-util', 'customize-preview', 'customize-selective-refresh' ), false, 1 );
    14841486
    1485     $scripts->add( 'customize-nav-menus', "/wp-admin/js/customize-nav-menus$suffix.js", array( 'jquery', 'wp-backbone', 'customize-controls', 'accordion', 'nav-menu' ), false, 1 );
     1487    $scripts->add( 'customize-nav-menus', "/wp-admin/js/customize-nav-menus$suffix.js", array( 'jquery', 'wp-backbone', 'customize-controls', 'accordion', 'nav-menu', 'wp-sanitize' ), false, 1 );
    14861488    $scripts->add( 'customize-preview-nav-menus', "/wp-includes/js/customize-preview-nav-menus$suffix.js", array( 'jquery', 'wp-util', 'customize-preview', 'customize-selective-refresh' ), false, 1 );
    14871489
     
    15811583        );
    15821584
    1583         $scripts->add( 'post', "/wp-admin/js/post$suffix.js", array( 'suggest', 'wp-lists', 'postbox', 'tags-box', 'underscore', 'word-count', 'wp-a11y' ), false, 1 );
     1585        $scripts->add( 'post', "/wp-admin/js/post$suffix.js", array( 'suggest', 'wp-lists', 'postbox', 'tags-box', 'underscore', 'word-count', 'wp-a11y', 'wp-sanitize' ), false, 1 );
    15841586        did_action( 'init' ) && $scripts->localize(
    15851587            'post',
     
    16941696        $scripts->set_translations( 'site-health' );
    16951697
    1696         $scripts->add( 'updates', "/wp-admin/js/updates$suffix.js", array( 'jquery', 'wp-util', 'wp-a11y' ), false, 1 );
     1698        $scripts->add( 'updates', "/wp-admin/js/updates$suffix.js", array( 'jquery', 'wp-util', 'wp-a11y', 'wp-sanitize' ), false, 1 );
    16971699        did_action( 'init' ) && $scripts->localize(
    16981700            'updates',
  • branches/5.2/tests/phpunit/tests/dependencies/scripts.php

    r44744 r45989  
    693693
    694694        $ver       = get_bloginfo( 'version' );
    695         $expected  = "<script type='text/javascript' src='/wp-admin/load-scripts.php?c=0&amp;load%5B%5D=jquery-core,jquery-migrate,wp-a11y&amp;ver={$ver}'></script>\n";
     695        $expected  = "<script type='text/javascript' src='/wp-admin/load-scripts.php?c=0&amp;load%5B%5D=jquery-core,jquery-migrate,wp-sanitize,wp-a11y&amp;ver={$ver}'></script>\n";
    696696        $expected .= "<script type='text/javascript'>\nconsole.log(\"before\");\n</script>\n";
    697697        $expected .= "<script type='text/javascript' src='http://example.com'></script>\n";
  • branches/5.2/tests/qunit/index.html

    r45147 r45989  
    7777        <script src="../../build/wp-includes/js/customize-models.js"></script>
    7878        <script src="../../build/wp-includes/js/shortcode.js"></script>
     79+       <script src="../../build/wp-includes/js/wp-sanitize.js"></script>
    7980        <script src="../../build/wp-admin/js/customize-controls.js"></script>
    8081        <script src="../../build/wp-includes/js/api-request.js"></script>
Note: See TracChangeset for help on using the changeset viewer.