Speed optimizations for is_serialized_string(). fixes #17129

git-svn-id: http://svn.automattic.com/wordpress/trunk@17779 1a063a9b-81f0-0310-95a4-ce76da25c4cd
This commit is contained in:
markjaquith 2011-04-30 04:41:56 +00:00
parent 7e7d8d7cd4
commit ce344a28da
1 changed files with 12 additions and 2 deletions

View File

@ -278,9 +278,19 @@ function is_serialized_string( $data ) {
if ( !is_string( $data ) ) if ( !is_string( $data ) )
return false; return false;
$data = trim( $data ); $data = trim( $data );
if ( preg_match( '/^s:[0-9]+:.*;$/s', $data ) ) // this should fetch all serialized strings $length = strlen( $data );
return true; if ( $length < 4 )
return false; return false;
elseif ( ':' !== $data[1] )
return false;
elseif ( ';' !== $data[$length-1] )
return false;
elseif ( $data[0] !== 's' )
return false;
elseif ( '"' !== $data[$length-2] )
return false;
else
return true;
} }
/** /**