Make WordPress Core


Ignore:
Timestamp:
09/11/2013 07:22:05 AM (11 years ago)
Author:
dd32
Message:

Add a set of helpers to turn the behaviour of mbstring.func_overload off when needed. Fixes #25259

File:
1 edited

Legend:

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

    r25344 r25346  
    41314131    return $charset;
    41324132}
     4133
     4134/**
     4135 * Sets the mbstring internal encoding to a binary safe encoding whne func_overload is enabled.
     4136 *
     4137 * When mbstring.func_overload is in use for multi-byte encodings, the results from strlen() and
     4138 * similar functions respect the utf8 characters, causing binary data to return incorrect lengths.
     4139 *
     4140 * This function overrides the mbstring encoding to a binary-safe encoding, and resets it to the
     4141 * users expected encoding afterwards through the `reset_mbstring_encoding` function.
     4142 *
     4143 * It is safe to recursively call this function, however each `mbstring_binary_safe_encoding()`
     4144 * call must be followed up with an equal number of `reset_mbstring_encoding()` calls.
     4145 *
     4146 * @see reset_mbstring_encoding()
     4147 *
     4148 * @since 3.7.0
     4149 *
     4150 * @param bool $reset Whether to reset the encoding back to a previously-set encoding.
     4151 */
     4152function mbstring_binary_safe_encoding( $reset = false ) {
     4153    static $encodings = array();
     4154    static $overloaded = null;
     4155
     4156    if ( is_null( $overloaded ) )
     4157        $overloaded = function_exists( 'mb_internal_encoding' ) && ( ini_get( 'mbstring.func_overload' ) & 2 );
     4158
     4159    if ( false === $overloaded )
     4160        return;
     4161
     4162    if ( ! $reset ) {
     4163        $encoding = mb_internal_encoding();
     4164        array_push( $encodings, $encoding );
     4165        mb_internal_encoding( 'ISO-8859-1' );
     4166    }
     4167
     4168    if ( $reset && $encodings ) {
     4169        $encoding = array_pop( $encodings );
     4170        mb_internal_encoding( $encoding );
     4171    }
     4172}
     4173
     4174/**
     4175 * Resets the mbstring internal encoding to a users previously set encoding.
     4176 *
     4177 * @see mbstring_binary_safe_encoding()
     4178 *
     4179 * @since 3.7.0
     4180 */
     4181function reset_mbstring_encoding() {
     4182    mbstring_binary_safe_encoding( true );
     4183}
Note: See TracChangeset for help on using the changeset viewer.