WordPress.org

Make WordPress Core

Changeset 10376


Ignore:
Timestamp:
01/19/2009 04:40:12 AM (9 years ago)
Author:
azaozz
Message:

Fix incorrect quote style in wp_specialchars, props sambauers, see #8767

File:
1 edited

Legend:

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

    r10370 r10376  
    213213    }
    214214
     215    // Account for the previous behaviour of the function when the $quote_style is not an accepted value
     216    if ( empty( $quote_style ) ) {
     217        $quote_style = ENT_NOQUOTES;
     218    } elseif ( !in_array( $quote_style, array( 0, 2, 3, 'single', 'double' ), true ) ) {
     219        $quote_style = ENT_QUOTES;
     220    }
     221
    215222    // Store the site charset as a static to avoid multiple calls to wp_load_alloptions()
    216223    if ( !$charset ) {
     
    226233    }
    227234
    228     switch ( $quote_style ) {
    229         case ENT_QUOTES:
    230         default:
    231             $quote_style = ENT_QUOTES;
    232             $_quote_style = ENT_QUOTES;
    233             break;
    234         case ENT_COMPAT:
    235         case 'double':
    236             $quote_style = ENT_COMPAT;
    237             $_quote_style = ENT_COMPAT;
    238             break;
    239         case 'single':
    240             $quote_style = ENT_NOQUOTES;
    241             $_quote_style = 'single';
    242             break;
    243         case ENT_NOQUOTES:
    244         case false:
    245         case 0:
    246         case '':
    247         case null:
    248             $quote_style = ENT_NOQUOTES;
    249             $_quote_style = ENT_NOQUOTES;
    250             break;
     235    $_quote_style = $quote_style;
     236
     237    if ( $quote_style === 'double' ) {
     238        $quote_style = ENT_COMPAT;
     239        $_quote_style = ENT_COMPAT;
     240    } elseif ( $quote_style === 'single' ) {
     241        $quote_style = ENT_NOQUOTES;
    251242    }
    252243
     
    297288    if ( strpos( $string, '&' ) === false ) {
    298289        return $string;
     290    }
     291
     292    // Match the previous behaviour of wp_specialchars() when the $quote_style is not an accepted value
     293    if ( empty( $quote_style ) ) {
     294        $quote_style = ENT_NOQUOTES;
     295    } elseif ( !in_array( $quote_style, array( 0, 2, 3, 'single', 'double' ), true ) ) {
     296        $quote_style = ENT_QUOTES;
    299297    }
    300298
     
    307305    $others_preg = array( '/&#0*60;/'  => '<', '/&#0*62;/'  => '>', '/&#0*38;/'  => '&', '/&#x0*26;/i' => '&' );
    308306
    309     switch ( $quote_style ) {
    310         case ENT_QUOTES:
    311         default:
    312             $translation = array_merge( $single, $double, $others );
    313             $translation_preg = array_merge( $single_preg, $double_preg, $others_preg );
    314             break;
    315         case ENT_COMPAT:
    316         case 'double':
    317             $translation = array_merge( $double, $others );
    318             $translation_preg = array_merge( $double_preg, $others_preg );
    319             break;
    320         case 'single':
    321             $translation = array_merge( $single, $others );
    322             $translation_preg = array_merge( $single_preg, $others_preg );
    323             break;
    324         case ENT_NOQUOTES:
    325         case false:
    326         case 0:
    327         case '':
    328         case null:
    329             $translation = $others;
    330             $translation_preg = $others_preg;
    331             break;
     307    if ( $quote_style === ENT_QUOTES ) {
     308        $translation = array_merge( $single, $double, $others );
     309        $translation_preg = array_merge( $single_preg, $double_preg, $others_preg );
     310    } elseif ( $quote_style === ENT_COMPAT || $quote_style === 'double' ) {
     311        $translation = array_merge( $double, $others );
     312        $translation_preg = array_merge( $double_preg, $others_preg );
     313    } elseif ( $quote_style === 'single' ) {
     314        $translation = array_merge( $single, $others );
     315        $translation_preg = array_merge( $single_preg, $others_preg );
     316    } elseif ( $quote_style === ENT_NOQUOTES ) {
     317        $translation = $others;
     318        $translation_preg = $others_preg;
    332319    }
    333320
Note: See TracChangeset for help on using the changeset viewer.