diff options
author | Matthieu Aubry <matt@piwik.org> | 2016-03-08 16:58:04 +0300 |
---|---|---|
committer | Matthieu Aubry <matt@piwik.org> | 2016-03-08 16:58:04 +0300 |
commit | f8415f6aca65a7e126eaa24c61b7fe97e8a3339d (patch) | |
tree | 97b547b05a53fec005412fce83a2dbc32059b73c | |
parent | 236281cbeb87dd15dc0d393568e9932ac9a9ed9b (diff) | |
parent | b66433a7e4a09670d0e3a9480692bb919dcb0db0 (diff) |
Merge pull request #9894 from piwik/inichain
Prevents possible errors in IniFileChain::arrayUnmerge
-rw-r--r-- | core/Config/IniFileChain.php | 8 | ||||
-rw-r--r-- | tests/PHPUnit/Unit/Config/IniFileChainTest.php | 48 |
2 files changed, 56 insertions, 0 deletions
diff --git a/core/Config/IniFileChain.php b/core/Config/IniFileChain.php index b69154049f..1de3f4308e 100644 --- a/core/Config/IniFileChain.php +++ b/core/Config/IniFileChain.php @@ -347,6 +347,14 @@ class IniFileChain // return key/value pairs for keys in both $modified and $original, but values differ // ignore keys that are in $original but not in $modified + if (empty($original) || !is_array($original)) { + $original = array(); + } + + if (empty($modified) || !is_array($modified)) { + $modified = array(); + } + return array_udiff_assoc($modified, $original, array(__CLASS__, 'compareElements')); } diff --git a/tests/PHPUnit/Unit/Config/IniFileChainTest.php b/tests/PHPUnit/Unit/Config/IniFileChainTest.php index 137b6c234d..252288e979 100644 --- a/tests/PHPUnit/Unit/Config/IniFileChainTest.php +++ b/tests/PHPUnit/Unit/Config/IniFileChainTest.php @@ -122,6 +122,54 @@ class IniFileChainTest extends PHPUnit_Framework_TestCase $this->assertEquals(serialize($b), serialize($diff), $description); } + /** + * Dataprovider for testArrayUnmerge Invalid Data + * @return array + */ + public function getArrayUnmergeInvalidData() + { + return array( + array('modified invalid string', array( + array(), + '', + array(), + )), + array('modified invalid int', array( + array('login' => 'root', 'password' => 'b33r'), + 17, + array(), + + )), + array('original invalid string', array( + '', + array(), + array(), + )), + array('original invalid int', array( + 17, + array('login' => 'root', 'password' => 'b33r'), + array('login' => 'root', 'password' => 'b33r'), + )), + array('both invalid', array( + 17, + '', + array(), + )), + ); + } + + /** + * @dataProvider getArrayUnmergeInvalidData + */ + public function test_ArrayUnmerge_CanHandleInvalidData($description, $test) + { + $configWriter = new IniFileChain(array(), null); + + list($a, $b, $c) = $test; + + $this->assertEquals($c, $configWriter->arrayUnmerge($a, $b), $description); + } + public function getMergingTestData() { return array( |