[wp-trac] [WordPress Trac] #16597: Bug in the maybe_serialize() function - it serializing also serailize objects.

WordPress Trac wp-trac at lists.automattic.com
Sat Feb 19 17:46:11 UTC 2011


#16597: Bug in the maybe_serialize() function - it serializing also serailize
objects.
--------------------------+-----------------------------
 Reporter:  maorb         |      Owner:
     Type:  defect (bug)  |     Status:  new
 Priority:  normal        |  Milestone:  Awaiting Review
Component:  Formatting    |    Version:  3.0.5
 Severity:  major         |   Keywords:
--------------------------+-----------------------------
 Hi,

 I have discovered this bug by accident, when trying to import posts using
 the csv importer plugin.
 One of my lines contained a serialized array to be saved.
 The serialized data was ok, but saved to the db with a prefix of
 '''s:196:"''' and suffix of '''";'''.
 The reason is that the '''add_post_meta()''' function  uses the
 '''add_metadata()''' , which uses the '''maybe_serialize()''' function to
 determine if need to serialize or not.
 The thing is that it is serializing anyway!

 Look at wp-includes/functions.php, lines 1005-1013 -
 {{{
 function maybe_serialize( $data ) {
         if ( is_array( $data ) || is_object( $data ) )
                 return serialize( $data );

         if ( is_serialized( $data ) )
                 return serialize( $data );

         return $data;
 }

 }}}


 It says to serialize also if the data is_serialized....
 {{{
 if ( is_serialized( $data ) )
                 return serialize( $data );

 }}}

 The correct should be -
 {{{
 function maybe_serialize( $data ) {
         if ( is_array( $data ) || is_object( $data ) )
                 return serialize( $data );

         if ( is_serialized( $data ) )
                 return $data ;

         return $data;
 }

 }}}

 Otherwise, the data is being serialized twice and then WP can't show the
 real unserialized data ..

 After I changed it and rechecked passing serialized data to the
 add_meta_data() function - it all went ok.

 This should be fixed in core.

 Here is a reference also in the forums
 http://wordpress.org/support/topic/plugin-csv-importer-escaping-quotation-
 marks

 Thanks,
 Maor

-- 
Ticket URL: <http://core.trac.wordpress.org/ticket/16597>
WordPress Trac <http://core.trac.wordpress.org/>
WordPress blogging software


More information about the wp-trac mailing list