Ticket #8767: filters-compat-fixes.patch

File filters-compat-fixes.patch, 3.6 KB (added by sambauers, 4 years ago)
  • wp-includes/formatting.php

     
    212212                return $string; 
    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 ) { 
    217224                static $_charset; 
     
    225232                $charset = 'UTF-8'; 
    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 
    253244        // Handle double encoding ourselves 
     
    298289                return $string; 
    299290        } 
    300291 
     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; 
     297        } 
     298 
    301299        // More complete than get_html_translation_table( HTML_SPECIALCHARS ) 
    302300        $single = array( '''  => '\'', ''' => '\'' ); 
    303301        $single_preg = array( '/&#0*39;/'  => ''', '/&#x0*27;/i' => ''' ); 
     
    306304        $others = array( '&lt;'   => '<', '&#060;'  => '<', '&gt;'   => '>', '&#062;'  => '>', '&amp;'  => '&', '&#038;'  => '&', '&#x26;' => '&' ); 
    307305        $others_preg = array( '/&#0*60;/'  => '&#060;', '/&#0*62;/'  => '&#062;', '/&#0*38;/'  => '&#038;', '/&#x0*26;/i' => '&#x26;' ); 
    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 
    334321        // Remove zero padding on numeric entities