From 499c6b6a2c3ad04182deead667511b262c6e52fe Mon Sep 17 00:00:00 2001 From: Roland Gruber Date: Sun, 2 Jul 2017 09:35:27 +0200 Subject: [PATCH] fixed issues with duplicating empty type and module settings --- lam/lib/config.inc | 8 ++++---- lam/tests/lib/LAMConfigTest.php | 14 ++++++++++++++ 2 files changed, 18 insertions(+), 4 deletions(-) diff --git a/lam/lib/config.inc b/lam/lib/config.inc index eb57ad0b..a2595af5 100644 --- a/lam/lib/config.inc +++ b/lam/lib/config.inc @@ -643,24 +643,24 @@ class LAMConfig { else { $subKeyword = $parts[1]; $startIndex = $startIndex + strlen($subKeyword) + 2; + $option = substr($line, $startIndex); + if (empty($option)) { + continue; + } // module settings if ($keyword == 'modules') { - $option = substr($line, $startIndex); $this->moduleSettings[$subKeyword] = explode(LAMConfig::LINE_SEPARATOR, $option); } // type settings if ($keyword == 'types') { - $option = substr($line, $startIndex); $this->typeSettings[$subKeyword] = $option; } // tool settings if ($keyword == 'tools') { - $option = substr($line, $startIndex); $this->toolSettings[$subKeyword] = $option; } // job settings if ($keyword == 'jobs') { - $option = substr($line, $startIndex); $this->jobSettings[$subKeyword] = explode(LAMConfig::LINE_SEPARATOR, $option); } } diff --git a/lam/tests/lib/LAMConfigTest.php b/lam/tests/lib/LAMConfigTest.php index f04ff38a..9689b3ec 100644 --- a/lam/tests/lib/LAMConfigTest.php +++ b/lam/tests/lib/LAMConfigTest.php @@ -699,6 +699,20 @@ class LAMConfigTest extends PHPUnit_Framework_TestCase { $this->assertFalse(empty($token)); } + /** + * Checks that number of settings stays constant over multiple saves. + */ + public function testMultiSave() { + $sizeModSettings = sizeof($this->lAMConfig->get_moduleSettings()); + $sizeTypeSettings = sizeof($this->lAMConfig->get_typeSettings()); + $this->doSave(); + $this->assertEquals($sizeModSettings, sizeof($this->lAMConfig->get_moduleSettings())); + $this->assertEquals($sizeTypeSettings, sizeof($this->lAMConfig->get_typeSettings())); + $this->doSave(); + $this->assertEquals($sizeModSettings, sizeof($this->lAMConfig->get_moduleSettings())); + $this->assertEquals($sizeTypeSettings, sizeof($this->lAMConfig->get_typeSettings())); + } + /** * Saves the config */