From dc7228f7b0a8b1fa8c92e5a8bca4e9cbcdf11561 Mon Sep 17 00:00:00 2001 From: Mark Jaquith Date: Sat, 30 Apr 2011 04:41:56 +0000 Subject: [PATCH] Speed optimizations for is_serialized_string(). fixes #17129 git-svn-id: https://develop.svn.wordpress.org/trunk@17779 602fd350-edb4-49c9-b593-d223f7449a82 --- wp-includes/functions.php | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/wp-includes/functions.php b/wp-includes/functions.php index 5dc9c12759..cc0dbebc77 100644 --- a/wp-includes/functions.php +++ b/wp-includes/functions.php @@ -278,9 +278,19 @@ function is_serialized_string( $data ) { if ( !is_string( $data ) ) return false; $data = trim( $data ); - if ( preg_match( '/^s:[0-9]+:.*;$/s', $data ) ) // this should fetch all serialized strings + $length = strlen( $data ); + if ( $length < 4 ) + 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; - return false; } /**