Make WordPress Core

Ticket #9930: 9930.2.patch

File 9930.2.patch, 2.3 KB (added by hakre, 15 years ago)

Refreshed against trunk

  • wp-includes/functions.php

     
    217217}
    218218
    219219/**
    220  * Check value to find if it was serialized.
     220 * Check if value is serialized.
    221221 *
    222222 * If $data is not an string, then returned value will always be false.
    223223 * Serialized data is always a string.
     224 *
     225 * NOTICE: There can be no guarantee wether the data passed was not
     226 * just a string even if this function returns true.
    224227 *
    225228 * @since 2.0.5
    226229 *
    227230 * @param mixed $data Value to check to see if was serialized.
    228  * @return bool False if not serialized and true if it was.
     231 * @return bool False if not serialized and true if.
    229232 */
    230233function is_serialized( $data ) {
    231         // if it isn't a string, it isn't serialized
    232234        if ( !is_string( $data ) )
    233235                return false;
    234236        $data = trim( $data );
    235237        if ( 'N;' == $data )
    236                 return true;
    237         if ( function_exists('strpbrk') ) {
    238                 if ( strlen($data) > 1 && strpbrk($data,'adObis') == $data && $data[1] == ':' ) {
    239                         $badions = array();
    240                         $badions[1] = $data[0];
    241                 } else {
    242                         return false;
    243                 }
    244         } elseif ( !preg_match( '/^([adObis]):/', $data, $badions ) ) {
     238                return true; # NULL; fixed length: 2
     239        if ( strlen( $data ) < 4 )
    245240                return false;
     241        if ( ':' !== $data[1] )
     242                return false;
     243        $type = $data[0];
     244        if ( false === strpos('abdiOs', $type ) )
     245                return false;
     246
     247        switch ( $type ) {
     248                case 'a' : # array; min length: 6
     249                        return (bool) preg_match( '/^a:[0-9]+:{.*}$/s', $data );
     250                case 'b' : # bool; min length: 4
     251                case 'd' : # double; min length: 4
     252                case 'i' : # integer; min length: 4
     253                        return (bool) preg_match( "/^{$type}:[0-9.E+-]+;\$/", $data );
     254                case 'O' : # object; min length 12
     255                        return (bool) preg_match( '/^O:[0-9]+:"[a-zA-Z_\x7f-\xff][a-zA-Z0-9_\x7f-\xff]*":[0-9]+:{.*}$/s', $data );
     256                case 's' : # string; min length 7
     257                        return (bool) preg_match( '/^s:[0-9]+:".*";$/s', $data );
    246258        }
    247         switch ( $badions[1] ) {
    248                 case 'a' :
    249                 case 'O' :
    250                 case 's' :
    251                         if ( preg_match( "/^{$badions[1]}:[0-9]+:.*[;}]\$/s", $data ) )
    252                                 return true;
    253                         break;
    254                 case 'b' :
    255                 case 'i' :
    256                 case 'd' :
    257                         if ( preg_match( "/^{$badions[1]}:[0-9.E-]+;\$/", $data ) )
    258                                 return true;
    259                         break;
    260         }
    261259        return false;
    262260}
    263261