[pLog-svn] r3810 - in plog/trunk/class: config test/tests/config
oscar at devel.lifetype.net
oscar at devel.lifetype.net
Wed Jul 26 12:11:03 GMT 2006
Author: oscar
Date: 2006-07-26 12:11:03 +0000 (Wed, 26 Jul 2006)
New Revision: 3810
Modified:
plog/trunk/class/config/configfilestorage.class.php
plog/trunk/class/test/tests/config/configfilestorage_test.class.php
Log:
added some more cases and fixed one of them, where values saved with single quotes (') were not being escaped properly.
Modified: plog/trunk/class/config/configfilestorage.class.php
===================================================================
--- plog/trunk/class/config/configfilestorage.class.php 2006-07-26 12:01:11 UTC (rev 3809)
+++ plog/trunk/class/config/configfilestorage.class.php 2006-07-26 12:11:03 UTC (rev 3810)
@@ -201,6 +201,9 @@
// now we have to process each of the lines
$contents = $f->readFile();
+
+ // escape the value
+ $value = str_replace( "'", "\'", $value );
$i = 0;
$result = Array();
@@ -239,6 +242,7 @@
// the only thing we have to do know is save the contents of $result
// to the output file
+ //$result = str_replace( "'", "\\'", $result );
$f->writeLines( $result );
return true;
Modified: plog/trunk/class/test/tests/config/configfilestorage_test.class.php
===================================================================
--- plog/trunk/class/test/tests/config/configfilestorage_test.class.php 2006-07-26 12:01:11 UTC (rev 3809)
+++ plog/trunk/class/test/tests/config/configfilestorage_test.class.php 2006-07-26 12:11:03 UTC (rev 3810)
@@ -143,14 +143,52 @@
* test whether new values for keys defined with double quotes are saved properly back to the file
*/
function testSaveDoubleQuotesValue()
+ {
+ // open and load the file
+ $cf = new ConfigFileStorage( Array( "file" => $this->file1 ));
+
+ // and save a new one
+ $newValue = "This is the value for test_key_3";
+ $newKey = "test_key_3";
+ $cf->setValue( $newKey, $newValue );
+ $cf->save();
+
+ // reopen and load the file
+ $cf2 = new ConfigFileStorage( Array( "file" => $this->file1 ));
+ $this->assertEquals( $newValue, $cf2->getValue( $newKey ),
+ "$newKey was not saved properly to file ".$this->file1 );
+ }
+
+ /**
+ * Saves a value with single quotes, to check whether they're being escaped properly
+ */
+ function testSaveValueWithSingleQuotes()
{
- include_once( PLOG_CLASS_PATH."class/file/file.class.php" );
+ // open and load the file
+ $cf = new ConfigFileStorage( Array( "file" => $this->file1 ));
+ // and save a new one
+ $newValue = "This 'key' has plenty of 'single' quotes";
+ $newKey = "test_key_3";
+ $cf->setValue( $newKey, $newValue );
+ $cf->save();
+
+ // reopen and load the file
+ $cf2 = new ConfigFileStorage( Array( "file" => $this->file1 ));
+ $this->assertEquals( $newValue, $cf2->getValue( $newKey ),
+ "$newKey was not saved properly to file ".$this->file1 );
+ }
+
+ /**
+ * Saves a value with double quotes, to check whether they're being escaped properly
+ */
+ function testSaveValueWithDoubleQuotes()
+ {
// open and load the file
$cf = new ConfigFileStorage( Array( "file" => $this->file1 ));
// and save a new one
- $newValue = "This is the value for test_key_3";
+ $newValue = "This \"key\" has plenty of \"single\" quotes";
$newKey = "test_key_3";
$cf->setValue( $newKey, $newValue );
$cf->save();
@@ -158,7 +196,27 @@
// reopen and load the file
$cf2 = new ConfigFileStorage( Array( "file" => $this->file1 ));
$this->assertEquals( $newValue, $cf2->getValue( $newKey ),
- "$newKey was not saved properly to file ".$this->file1 );
+ "$newKey was not saved properly to file ".$this->file1 );
+ }
+
+ /**
+ * Saves a value with a dollar sign
+ */
+ function testSaveValueWithDollarSign()
+ {
+ // open and load the file
+ $cf = new ConfigFileStorage( Array( "file" => $this->file1 ));
+
+ // and save a new one
+ $newValue = "This key has a dollar sign $";
+ $newKey = "test_key_3";
+ $cf->setValue( $newKey, $newValue );
+ $cf->save();
+
+ // reopen and load the file
+ $cf2 = new ConfigFileStorage( Array( "file" => $this->file1 ));
+ $this->assertEquals( $newValue, $cf2->getValue( $newKey ),
+ "$newKey was not saved properly to file ".$this->file1 );
}
}
?>
\ No newline at end of file
More information about the pLog-svn
mailing list