From 5ff23f02b80ec6ddee28dee869171ee8e3656b7c Mon Sep 17 00:00:00 2001 From: ArthurHoaro Date: Mon, 20 Jun 2016 18:30:37 +0200 Subject: [PATCH] Add closing PHP tags to JSON config files --- application/config/ConfigJson.php | 15 ++++++++++++++- tests/config/ConfigJsonTest.php | 2 +- tests/utils/config/configInvalid.json.php | 1 + tests/utils/config/configJson.json.php | 2 ++ 4 files changed, 18 insertions(+), 2 deletions(-) diff --git a/application/config/ConfigJson.php b/application/config/ConfigJson.php index 94693c86..d07fefee 100644 --- a/application/config/ConfigJson.php +++ b/application/config/ConfigJson.php @@ -17,6 +17,7 @@ function read($filepath) } $data = file_get_contents($filepath); $data = str_replace(self::getPhpHeaders(), '', $data); + $data = str_replace(self::getPhpSuffix(), '', $data); $data = json_decode($data, true); if ($data === null) { $error = json_last_error(); @@ -32,7 +33,7 @@ function write($filepath, $conf) { // JSON_PRETTY_PRINT is available from PHP 5.4. $print = defined('JSON_PRETTY_PRINT') ? JSON_PRETTY_PRINT : 0; - $data = self::getPhpHeaders() . json_encode($conf, $print); + $data = self::getPhpHeaders() . json_encode($conf, $print) . self::getPhpSuffix(); if (!file_put_contents($filepath, $data)) { throw new IOException( $filepath, @@ -62,4 +63,16 @@ public static function getPhpHeaders() { return ''; + } } diff --git a/tests/config/ConfigJsonTest.php b/tests/config/ConfigJsonTest.php index 359e9112..99c88820 100644 --- a/tests/config/ConfigJsonTest.php +++ b/tests/config/ConfigJsonTest.php @@ -88,7 +88,7 @@ public function testWriteNew() } else { $expected = '{"credentials":{"login":"root"},"resource":{"datastore":"data\/datastore.php"},"redirector":{"url":"lala"},"plugins":{"WALLABAG_VERSION":"1"}}'; } - $expected = ConfigJson::getPhpHeaders() . $expected; + $expected = ConfigJson::getPhpHeaders() . $expected . ConfigJson::getPhpSuffix(); $this->assertEquals($expected, file_get_contents($dataFile)); unlink($dataFile); } diff --git a/tests/utils/config/configInvalid.json.php b/tests/utils/config/configInvalid.json.php index c53e471d..167f2168 100644 --- a/tests/utils/config/configInvalid.json.php +++ b/tests/utils/config/configInvalid.json.php @@ -2,3 +2,4 @@ { bad: bad, } +*/ ?> \ No newline at end of file diff --git a/tests/utils/config/configJson.json.php b/tests/utils/config/configJson.json.php index c54882c3..06a302e8 100644 --- a/tests/utils/config/configJson.json.php +++ b/tests/utils/config/configJson.json.php @@ -30,3 +30,5 @@ "WALLABAG_VERSION": 1 } } +*/ ?> +