WordPress.org

Make WordPress Core

Changeset 4438


Ignore:
Timestamp:
10/31/2006 08:24:09 AM (12 years ago)
Author:
markjaquith
Message:

Catch NULL, bool, and integer values in is_serialized(). Props mdawaffe. fixes #3310

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/wp-includes/functions.php

    r4435 r4438  
    164164
    165165function is_serialized($data) {
    166     if ( !is_string($data) ) // if it isn't a string, it isn't serialized
     166    // if it isn't a string, it isn't serialized
     167    if ( !is_string($data) )
    167168        return false;
    168169    $data = trim($data);
    169     if ( preg_match("/^[adobis]:[0-9]+:.*[;}]/si",$data) ) // this should fetch all legitimately serialized data
     170    if ( 'N;' == $data )
    170171        return true;
     172    if ( !preg_match('/^([adObis]):/', $data, $badions) )
     173        return false;
     174    switch ( $badions[1] ) :
     175    case 'a' :
     176    case 'O' :
     177    case 's' :
     178        if ( preg_match("/^{$badions[1]}:[0-9]+:.*[;}]\$/s", $data) )
     179            return true;
     180        break;
     181    case 'b' :
     182    case 'i' :
     183    case 'd' :
     184        if ( preg_match("/^{$badions[1]}:[0-9.E-]+;\$/", $data) )
     185            return true;
     186        break;
     187    endswitch;
    171188    return false;
    172189}
    173190
    174191function is_serialized_string($data) {
    175     if ( !is_string($data) ) // if it isn't a string, it isn't a serialized string
     192    // if it isn't a string, it isn't a serialized string
     193    if ( !is_string($data) )
    176194        return false;
    177195    $data = trim($data);
    178     if ( preg_match("/^s:[0-9]+:.*[;}]/si",$data) ) // this should fetch all serialized strings
     196    if ( preg_match('/^s:[0-9]+:.*;$/s',$data) ) // this should fetch all serialized strings
    179197        return true;
    180198    return false;
     
    12031221    return $input;
    12041222}
    1205 
    12061223?>
Note: See TracChangeset for help on using the changeset viewer.