From 31dd2e70f05f5d729d9d20a81a76303844bec3a8 Mon Sep 17 00:00:00 2001 From: Sergey Biryukov Date: Fri, 13 Mar 2020 21:12:01 +0000 Subject: [PATCH] General: Trim the input data in `maybe_unserialize()`, for consistency with `is_serialized()`. Props pbearne, mikeschroder. Fixes #36416. git-svn-id: https://develop.svn.wordpress.org/trunk@47454 602fd350-edb4-49c9-b593-d223f7449a82 --- src/wp-includes/functions.php | 2 +- tests/phpunit/tests/functions.php | 1 + 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/src/wp-includes/functions.php b/src/wp-includes/functions.php index 8a91d152bf..dad7f15862 100644 --- a/src/wp-includes/functions.php +++ b/src/wp-includes/functions.php @@ -616,7 +616,7 @@ function maybe_serialize( $data ) { */ function maybe_unserialize( $data ) { if ( is_serialized( $data ) ) { // Don't attempt to unserialize data that wasn't serialized going in. - return @unserialize( $data ); + return @unserialize( trim( $data ) ); } return $data; diff --git a/tests/phpunit/tests/functions.php b/tests/phpunit/tests/functions.php index c00439d092..db691131ed 100644 --- a/tests/phpunit/tests/functions.php +++ b/tests/phpunit/tests/functions.php @@ -291,6 +291,7 @@ class Tests_Functions extends WP_UnitTestCase { ), true, ), + array( ' s:25:"this string is serialized"; ', true ), ); }