﻿id	summary	reporter	owner	description	type	status	priority	milestone	component	version	severity	resolution	keywords	cc
16597	Bug in the maybe_serialize() function - it serializing also serailize objects.	maorb	nacin	"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"	defect (bug)	closed	normal	3.3	Formatting	3.0.5	major	fixed	has-patch	maor@…
