• theicemage

    (@theicemage)


    I set up my fields and then exported them to help troubleshoot an unrelated issue. Once I saved the export, I could not go back in and export another set of fields. I found that if a select list contains an apostrophe (‘), the object can’t be deserialized. When exporting, the code needs to escape this character. Sample excerpt follows:

    {s:5:”label”;s:6:”Server”;s:3:”key”;s:6:”server”;s:4:”slug”;s:0:””;s:10:”field_type”;s:6:”select”;s:6:”values”;s:69:”Alpha, Bravo, Charlie, Delta, Echo, Al’co, Br’co, Ch’co, De’co, Ec’co”;

    That will break if saved as part of an export to a file. The following will not break:

    {s:5:”label”;s:6:”Server”;s:3:”key”;s:6:”server”;s:4:”slug”;s:0:””;s:10:”field_type”;s:6:”select”;s:6:”values”;s:69:”Alpha, Bravo, Charlie, Delta, Echo, Al\’co, Br\’co, Ch\’co, De\’co, Ec\’co”;

    I’m not sure what needs to be done with the s:69 character count once escapes are added. I suspect it need not change, but some testing around that would be good.

    https://www.ads-software.com/extend/plugins/more-fields/

Viewing 1 replies (of 1 total)
  • Danno040

    (@danno040)

    Well, I propose Base64 Encoding the string. That way any special characters will not break the import. Here’s a patch I put together, hopefully this helps you:

    --- ../tags/2.1/more-plugins/more-plugins-admin.php	2012-03-07 15:51:01.000000000 -0700
    +++ more-plugins/more-plugins-admin.php	2012-03-08 08:52:46.000000000 -0700
    @@ -235,9 +235,9 @@
     			$k = $this->keys[1];
     			$a = str_replace('-', '_', $k);
     			$f = $function . '_saved_' . $a;
    -			$j = maybe_serialize($data);
    +			$j = base64_encode( maybe_serialize($data) );
     			$export = "<?php \nadd_filter('$filter', '$f');\n";
    -			$export .= "function $f (\$d) {\$d['$k'] = maybe_unserialize('$j', true); return \$d; }\n?>";
    +			$export .= "function $f (\$d) {\$d['$k'] = maybe_unserialize( base64_decode('$j'), true); return \$d; }\n?>";
     			$filename = $a . '.php';
     			$dir = $this->dir . 'saved/';
Viewing 1 replies (of 1 total)
  • The topic ‘[Plugin: More Fields] Saved export breaks if select list contains apostrope’ is closed to new replies.