Make WordPress Core


Ignore:
Timestamp:
03/17/2014 08:08:25 PM (11 years ago)
Author:
nacin
Message:

In is_serialized(), use substr() rather than array access, for compatibility with multibyte overloading.

props SergeyBiryukov.
fixes #18007.

File:
1 edited

Legend:

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

    r27481 r27565  
    252252function is_serialized( $data, $strict = true ) {
    253253    // if it isn't a string, it isn't serialized
    254     if ( ! is_string( $data ) )
     254    if ( ! is_string( $data ) ) {
    255255        return false;
     256    }
    256257    $data = trim( $data );
    257     if ( 'N;' == $data )
     258    if ( 'N;' == $data ) {
    258259        return true;
    259     $length = strlen( $data );
    260     if ( $length < 4 )
     260    }
     261    if ( strlen( $data ) < 4 ) {
    261262        return false;
    262     if ( ':' !== $data[1] )
     263    }
     264    if ( ':' !== $data[1] ) {
    263265        return false;
     266    }
    264267    if ( $strict ) {
    265         $lastc = $data[ $length - 1 ];
    266         if ( ';' !== $lastc && '}' !== $lastc )
     268        $lastc = substr( $data, -1 );
     269        if ( ';' !== $lastc && '}' !== $lastc ) {
    267270            return false;
     271        }
    268272    } else {
    269273        $semicolon = strpos( $data, ';' );
     
    282286        case 's' :
    283287            if ( $strict ) {
    284                 if ( '"' !== $data[ $length - 2 ] )
     288                if ( '"' !== substr( $data, -2, 1 ) ) {
    285289                    return false;
     290                }
    286291            } elseif ( false === strpos( $data, '"' ) ) {
    287292                return false;
     
    310315function is_serialized_string( $data ) {
    311316    // if it isn't a string, it isn't a serialized string
    312     if ( !is_string( $data ) )
     317    if ( ! is_string( $data ) ) {
    313318        return false;
     319    }
    314320    $data = trim( $data );
    315     $length = strlen( $data );
    316     if ( $length < 4 )
     321    if ( strlen( $data ) < 4 ) {
    317322        return false;
    318     elseif ( ':' !== $data[1] )
     323    } elseif ( ':' !== $data[1] ) {
    319324        return false;
    320     elseif ( ';' !== $data[$length-1] )
     325    } elseif ( ';' !== substr( $data, -1 ) ) {
    321326        return false;
    322     elseif ( $data[0] !== 's' )
     327    } elseif ( $data[0] !== 's' ) {
    323328        return false;
    324     elseif ( '"' !== $data[$length-2] )
     329    } elseif ( '"' !== substr( $data, -2, 1 ) ) {
    325330        return false;
    326     else
     331    } else {
    327332        return true;
     333    }
    328334}
    329335
Note: See TracChangeset for help on using the changeset viewer.