Projects ⇒ Bugs ⇒ #826: Saving and then Loading an array to cache with string keys containing "'" ⇒ CPG Dragonfly™ CMS
Bug #826 Saving and then Loading an array to cache with string keys containing "'"
Project: Dragonfly 9.0.3 -> 9.3 Category: *CPG Core Issues
Submitted: Monday, July 10, 2006 (08:34:20) Modified: Friday, October 28, 2011 (08:31:48)
Status: Bogus Assigned to:
PHP Version: Irrelevant HTTPD Server: Apache 1.3

View/Vote Add Comment

by: PeLLaRaS
When you try to save an array to cache using the class Cache and the array contains string keys containing character ('), the array will be saved normally but when you try to load the array you will get a parse error.

Reproduce code:
In file includes/classes/cpg_cache.php under function _array_parse, at line 33:
$key = is_int($key) ? $key : "'$key'";
doesn't process the string the same way with value.

Should be change to (the same code that parse the $value):
if (!is_int($key)) { $key = str_replace('\\', "\\\\", trim($key)); $key = "'".ereg_replace("'", "\\'", $key)."'"; }

P.S. Why the need for trim()? If the original array contains space before or after a string key or value, shouldn't remain the same when you load the array?
by: NanoCaiordo
Correct way for handling single quotes
$str = "string that use ' single quote"; $str = 'string that use \' single quote';
by: PeLLaRaS
Yes, just try to save this string but try to save it
while it is a key in an array and not a value. Then try to load back the array.

$array = array('that\'s me' => 'tall'); Cache::array_save('array', 'module, $array); Cache::array_load('array', 'module, true);

it will give an error because the array was saved in the cache like this:
if (!defined('CPG_NUKE')) { exit; } $array = array( 'that's me' => 'tall' );
and as you wrote thats wrong
by: NanoCaiordo
This bug has been fixed in the CVS.

Snapshots of the sources are packaged every 6 hours; this change
will be in the next snapshot. You can grab the snapshot at the
Downloads section.

Thank you for the report, and for helping us to make Dragonfly 9.0.3 -> 9.1 better.
by: PeLLaRaS
why it will not be fixed?

May I suggest replacing the _array_parse function in the class cache with the native fuction var_export in php?
by: NanoCaiordo
I did forget to leave a comment, sorry.

if you really need single quotes use:
array('that\\\'s me' => 'tall');
User Info

Welcome Anonymous


Support for DragonflyCMS in a other languages: