Adding of backslashes when saving Preferences
A bug in 2.1.1, submitted by klaftertief on 22 September 2010
Announcement
Symphony's issue tracker has been moved to Github.
Issues are displayed here for reference only and cannot be created or edited.
Browse
Closed#407: Adding of backslashes when saving Preferences
Hm. I’m not sure if it’s a Symphony bug or an extension bug. Have to investigate.
Yep I hit this today with Search Index. I serialise an array (to a string) and then store this in a key in the config file:
http://github.com/nickdunn/search_index/blob/master/lib/class.search_index.php#L28
But it seems that on some occasions (I can’t determine when/why it does or does not occur) that backslashes multiply and multiply. I’m convinced it’s due to over/underzealous stripslashes
and/or addslashes
but that’s as far as I’ve got.
I noticed it with your Search Index extension as well, Nick. I temporarily (and I believe incorrectly) fixed it in line 86 of class.configuration.php
(__toString
method, used in saveConfig
of class.administration.php
) by stripping slashes before adding slashes again.
I’d be interested to see if this commit fixes it.
I figure that extensions get their values by using the get
function, and perhaps not all use the $index
parameter. I believe stripslashes
missing from the last return
is a bug/typo anyway, so adding it here should fix it.
EDIT Cancel that, that commit has now been reverted. It would seem if an extension just uses get
without specifying an $index
, it is up to the extension to apply stripslashes
to the values.
Shouldn’t the Configuration class just handle this though?
The slashes are saved into the config file, so this tells me that the stripslashes should occur during the write and not the read. The Search Index extension never calls get()
without specifying an $index
so I’m not convinced this is it.
When I save the config, I use the set('key', 'value')
method and then save()
. Perhaps my set
should strip slashes from the serialized array string it passes as the value.
Shouldn’t the Configuration class do this itself though? Would it be reliable?
Fixed this finally. The Configuration class now stripslashes
all values that are passed to it. addslashes
is run to save the Configuration to a file.
The reason this works is that the Configuration class is a bit backward in Symphony in that the config.php
file is loaded into the Configuration class using Configuration->setArray
. In this function, all the slashes that were added to save the file to disk are removed, resulting in a pure Configuration->_properties
array.
It is this Configuration->_properties
array that is used by the get
function to return the Configuration values, so the get
function does not have to worry about stripslashes
.
For extensions, they should never had to manually stripslashes
, this will be done when the Configuration array is saved out to config.php
This issue is closed.
Like in issue #393 Symphony keeps adding backslashes to the values of configuration data.