Make WordPress Core

Ticket #9930: 9930.patch

File 9930.patch, 1.9 KB (added by hakre, 15 years ago)
  • wp-includes/functions.php

     
    238238 *
    239239 * If $data is not an string, then returned value will always be false.
    240240 * Serialized data is always a string.
     241 *
     242 * NOTICE: There can be no guarantee wether the data passed was not
     243 * just a string even if this function returns true.
    241244 *
    242245 * @since 2.0.5
    243246 *
    244247 * @param mixed $data Value to check to see if was serialized.
    245  * @return bool False if not serialized and true if it was.
     248 * @return bool False if not serialized and true if.
    246249 */
    247250function is_serialized( $data ) {
    248         // if it isn't a string, it isn't serialized
    249251        if ( !is_string( $data ) )
    250252                return false;
    251         $data = trim( $data );
    252         if ( 'N;' == $data )
    253                 return true;
    254         if ( !preg_match( '/^([adObis]):/', $data, $badions ) )
     253
     254        if ( !preg_match( '/^([abdiOs]:|N;)/', $data, $matches ) )
    255255                return false;
    256         switch ( $badions[1] ) {
    257                 case 'a' :
    258                 case 'O' :
    259                 case 's' :
    260                         if ( preg_match( "/^{$badions[1]}:[0-9]+:.*[;}]\$/s", $data ) )
    261                                 return true;
    262                         break;
    263                 case 'b' :
    264                 case 'i' :
    265                 case 'd' :
    266                         if ( preg_match( "/^{$badions[1]}:[0-9.E-]+;\$/", $data ) )
    267                                 return true;
    268                         break;
     256
     257        $type = $matches[1][0];
     258
     259        switch ( $type ) {
     260                case 'a' : # array
     261                        return (bool) preg_match( '/^a:[0-9]+:{.*}$/s', $data );
     262                case 'b' : # bool
     263                case 'd' : # double     
     264                case 'i' : # integer
     265                        return (bool) preg_match( "/^{$type}:[0-9.E+-]+;\$/", $data );
     266                case 'N' : # NULL
     267                        return (bool) ( 'N;' == $data );
     268                case 'O' : # object
     269                        return (bool) preg_match( '/^O:[0-9]+:"[a-zA-Z_\x7f-\xff][a-zA-Z0-9_\x7f-\xff]*":[0-9]+:{.*}$/s', $data );
     270                case 's' : # string
     271                        return (bool) preg_match( '/^s:[0-9]+:".*";$/s', $data );
     272                default:
     273                        return false;
    269274        }
    270         return false;
    271275}
    272276
    273277/**