### Eclipse Workspace Patch 1.0
#P wordpress
|
|
|
228 | 228 | * @return mixed Unserialized data can be any type. |
229 | 229 | */ |
230 | 230 | function maybe_unserialize( $original ) { |
231 | | if ( is_serialized( $original ) ) // don't attempt to unserialize data that wasn't serialized going in |
| 231 | if ( is_serialized_maybe( $original ) ) // don't attempt to unserialize data that wasn't serialized going in |
232 | 232 | return @unserialize( $original ); |
233 | 233 | return $original; |
234 | 234 | } |
… |
… |
|
275 | 275 | return false; |
276 | 276 | } |
277 | 277 | |
| 278 | |
278 | 279 | /** |
| 280 | * Check if parameter is serialized of maybe serialized data. |
| 281 | * |
| 282 | * Will always return true if $data was serialized by maybe_serialize: |
| 283 | * $return = is_serialized_maybe( maybe_serialize( $data ) ); |
| 284 | * And it will always return false if not. |
| 285 | * |
| 286 | * @see maybe_serialize() |
| 287 | * |
| 288 | * @since 3.x.x |
| 289 | * |
| 290 | * @param mixed $data Data that might would have been serialized. |
| 291 | * @return bool |
| 292 | */ |
| 293 | function is_serialized_maybe( $data ) { |
| 294 | static $mapStart = array( 's'=>1, 'a'=>1, 'O'=>1 ); |
| 295 | if ( ! is_string( $data ) ) |
| 296 | return false; |
| 297 | $length = strlen( $data ); |
| 298 | if ( $length < 4 ) |
| 299 | return false; |
| 300 | $token = $data[0]; |
| 301 | if ( !isset($mapStart[$token]) ) |
| 302 | return false; |
| 303 | if ( ':' !== $data[1] ) |
| 304 | return false; |
| 305 | $lastc = $data[$length-1]; |
| 306 | if ( ';' !== $lastc && '}' !== $lastc ) |
| 307 | return false; |
| 308 | if ( 's' === $token ) |
| 309 | return (bool) '"' !== $data[$length-2]; |
| 310 | return (bool) preg_match( "/^{$token}:[0-9]+:/s", $data ); |
| 311 | } |
| 312 | |
| 313 | /** |
279 | 314 | * Check whether serialized data is of string type. |
280 | 315 | * |
281 | 316 | * @since 2.0.5 |