From: Timo Tijhof Date: Thu, 26 Jun 2014 23:03:22 +0000 (+0200) Subject: objectcache: Actually unserialize integers as integers in RedisBagOStuff X-Git-Tag: 1.31.0-rc.0~15199^2 X-Git-Url: https://git.cyclocoop.org/%7B%7B%20url_for%28?a=commitdiff_plain;h=eb0a3b78300cd1de8276a76f9b7ee11e6a60e226;p=lhc%2Fweb%2Fwiklou.git objectcache: Actually unserialize integers as integers in RedisBagOStuff Before: > SET (stored) GET > 5 5 (string) "5" > '5' 5 (string) "5" > 'x' s:1:"x"; (string) "x" After: > SET (stored) GET > 5 5 (int) 5 > '5' s:1:"5"; (string) "5" > 'x' s:1:"x"; (string) "x" Follows-up 2ceda41c5783ddc3cfb. Bug: 60563 Change-Id: I2bb09381b2bb733ac5a89175e053cb10eca68b08 --- diff --git a/includes/objectcache/RedisBagOStuff.php b/includes/objectcache/RedisBagOStuff.php index e770b73886..825c77b1e6 100644 --- a/includes/objectcache/RedisBagOStuff.php +++ b/includes/objectcache/RedisBagOStuff.php @@ -322,14 +322,14 @@ class RedisBagOStuff extends BagOStuff { $this->logRequest( 'incr', $key, $server, $result ); return $result; } - /** * @param mixed $data * @return string */ protected function serialize( $data ) { - // Ignore digit strings and ints so INCR/DECR work - return ( is_int( $data ) || ctype_digit( $data ) ) ? $data : serialize( $data ); + // Serialize anything but integers so INCR/DECR work + // Do not store integer-like strings as integers to avoid type confusion (bug 60563) + return is_int( $data ) ? $data : serialize( $data ); } /** @@ -337,8 +337,7 @@ class RedisBagOStuff extends BagOStuff { * @return mixed */ protected function unserialize( $data ) { - // Ignore digit strings and ints so INCR/DECR work - return ( is_int( $data ) || ctype_digit( $data ) ) ? $data : unserialize( $data ); + return ctype_digit( $data ) ? intval( $data ) : unserialize( $data ); } /**