Zend Framework

Zend_Config_Writer_Ini adds anti-slashes to strings

Details

  • Type: Bug Bug
  • Status: Resolved Resolved
  • Priority: Minor Minor
  • Resolution: Fixed
  • Affects Version/s: 1.7.5
  • Fix Version/s: 1.10.0
  • Component/s: Zend_Config_Writer
  • Labels:
    None

Description

Zend_Config_Writer_Ini adds anti-slashes to strings when it writes data into files the same as does Zend_Config_Writer_Array.
but it encloses the string in " " quotes.

Once you read the file, strings remain escaped with anti-slashes and you have to parse your Zend_Config object.

Workaround : in Zend_Config_Writer_Ini function's _prepareValue(), don't parse strings with addslashes().

Hope report correct and appropriate. its my first.

Activity

Hide
Robert Basic added a comment -

When reading an .ini file with parse_ini_file(), all double quotes - escaped or not - are removed: so str"ing becomes string and str\"ing becomes str\ing.

Talked with Ben about this, removing the addslashes() and throwing an Exception when a double quote is inside the stored value.

Show
Robert Basic added a comment - When reading an .ini file with parse_ini_file(), all double quotes - escaped or not - are removed: so str"ing becomes string and str\"ing becomes str\ing. Talked with Ben about this, removing the addslashes() and throwing an Exception when a double quote is inside the stored value.
Hide
Robert Basic added a comment -

Attached the diff which should fix this.

Show
Robert Basic added a comment - Attached the diff which should fix this.
Hide
Robert Basic added a comment -

Attached the diff

Show
Robert Basic added a comment - Attached the diff
Hide
Robert Basic added a comment -

Reassigning to Ben so he can commit the patch.

Show
Robert Basic added a comment - Reassigning to Ben so he can commit the patch.
Hide
Ken Chou added a comment -

double quotes in value may cause .ini file incorrect.

— reproduct code: —

require_once 'Zend/Config/Writer/Ini.php';
require_once 'Zend/Config/Ini.php';

$data = array(
'testKey' => 'test"quotes',
'nextKey' => 'blah,blah,blah...',
);
$file = 'test.ini';

$config = new Zend_Config($data);
// write
$options = array('config' => $config , 'filename' => $file);
$writer = new Zend_Config_Writer_Ini($options);
$writer->write();

// read
$config = new Zend_Config_Ini($file);
var_dump($config->toArray());

— expect result —
array(2) { ["testKey"]=> string(10) "testquotes" ["nextKey"]=> string(17) "blah,blah,blah..." }

— actual result —
array(1) { ["testKey"]=> string(39) "test\quotes nextKey = blah,blah,blah..." }

Show
Ken Chou added a comment - double quotes in value may cause .ini file incorrect. — reproduct code: — require_once 'Zend/Config/Writer/Ini.php'; require_once 'Zend/Config/Ini.php'; $data = array( 'testKey' => 'test"quotes', 'nextKey' => 'blah,blah,blah...', ); $file = 'test.ini'; $config = new Zend_Config($data); // write $options = array('config' => $config , 'filename' => $file); $writer = new Zend_Config_Writer_Ini($options); $writer->write(); // read $config = new Zend_Config_Ini($file); var_dump($config->toArray()); — expect result — array(2) { ["testKey"]=> string(10) "testquotes" ["nextKey"]=> string(17) "blah,blah,blah..." } — actual result — array(1) { ["testKey"]=> string(39) "test\quotes nextKey = blah,blah,blah..." }

People

Vote (1)
Watch (2)

Dates

  • Created:
    Updated:
    Resolved: