Make WordPress Core


Ignore:
Timestamp:
06/18/2015 09:59:10 PM (9 years ago)
Author:
wonderboymusic
Message:

Since PHP 5.2.3, the htmlspecialchars() function has an optional $double_encode parameter, which we can now use. This will save us a few expensive kses/html decoding calls.

Adds unit tests.

Props miqrogroove.
Fixes #17780.

File:
1 edited

Legend:

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

    r32800 r32850  
    689689    }
    690690
    691     // Handle double encoding ourselves
    692     if ( $double_encode ) {
    693         $string = @htmlspecialchars( $string, $quote_style, $charset );
    694     } else {
    695         // Decode & into &
    696         $string = wp_specialchars_decode( $string, $_quote_style );
    697 
    698         // Guarantee every &entity; is valid or re-encode the &
    699         $string = wp_kses_normalize_entities( $string );
    700 
    701         // Now re-encode everything except &entity;
    702         $string = preg_split( '/(&#?x?[0-9a-z]+;)/i', $string, -1, PREG_SPLIT_DELIM_CAPTURE );
    703 
    704         for ( $i = 0, $c = count( $string ); $i < $c; $i += 2 ) {
    705             $string[$i] = @htmlspecialchars( $string[$i], $quote_style, $charset );
    706         }
    707         $string = implode( '', $string );
    708     }
     691    $string = @htmlspecialchars( $string, $quote_style, $charset, $double_encode );
    709692
    710693    // Backwards compatibility
Note: See TracChangeset for help on using the changeset viewer.