From dd88d193b9e01f4518a21d9cd1d25b7575677c39 Mon Sep 17 00:00:00 2001 From: Philipp Date: Tue, 3 Jan 2023 15:36:36 +0100 Subject: [PATCH] Escape single quotes and backslashes --- src/Core/Config/Util/ConfigFileTransformer.php | 2 +- tests/datasets/config/B.node.config.php | 1 + ...figFileLoaderTest.php => ConfigFileManagerTest.php} | 10 ++++++++-- 3 files changed, 10 insertions(+), 3 deletions(-) rename tests/src/Core/Config/Cache/{ConfigFileLoaderTest.php => ConfigFileManagerTest.php} (98%) diff --git a/src/Core/Config/Util/ConfigFileTransformer.php b/src/Core/Config/Util/ConfigFileTransformer.php index 9b80991af6..282714df2a 100644 --- a/src/Core/Config/Util/ConfigFileTransformer.php +++ b/src/Core/Config/Util/ConfigFileTransformer.php @@ -75,7 +75,7 @@ class ConfigFileTransformer } elseif (is_numeric($value)) { $string .= $value . ","; } else { - $string .= sprintf('\'%s\',', $value); + $string .= sprintf('\'%s\',', addcslashes($value, '\'\\')); } $string .= PHP_EOL; diff --git a/tests/datasets/config/B.node.config.php b/tests/datasets/config/B.node.config.php index 94b2e3f12e..499e092a45 100644 --- a/tests/datasets/config/B.node.config.php +++ b/tests/datasets/config/B.node.config.php @@ -34,5 +34,6 @@ return [ 'theme' => 'frio', 'int' => 23, 'float' => 2.5, + 'with special chars' => 'I can\'t follow this "$&§%"$%§$%&\'[),', ], ]; diff --git a/tests/src/Core/Config/Cache/ConfigFileLoaderTest.php b/tests/src/Core/Config/Cache/ConfigFileManagerTest.php similarity index 98% rename from tests/src/Core/Config/Cache/ConfigFileLoaderTest.php rename to tests/src/Core/Config/Cache/ConfigFileManagerTest.php index aed55f429e..99049426bc 100644 --- a/tests/src/Core/Config/Cache/ConfigFileLoaderTest.php +++ b/tests/src/Core/Config/Cache/ConfigFileManagerTest.php @@ -28,7 +28,7 @@ use Friendica\Test\Util\VFSTrait; use Friendica\Core\Config\Util\ConfigFileManager; use org\bovigo\vfs\vfsStream; -class ConfigFileLoaderTest extends MockedTest +class ConfigFileManagerTest extends MockedTest { use VFSTrait; @@ -407,10 +407,13 @@ class ConfigFileLoaderTest extends MockedTest $configFileLoader->setupCache($configCache); + $specialChars = '!"§$%&/()(/&%$\'>set('system', 'test', 'it', Cache::SOURCE_DATA); $configCache->set('config', 'test', 'it', Cache::SOURCE_DATA); $configCache->set('system', 'test_2', 2, Cache::SOURCE_DATA); + $configCache->set('special_chars', 'special', $specialChars, Cache::SOURCE_DATA); $configFileLoader->saveData($configCache); // Reload the configCache with the new values @@ -424,7 +427,10 @@ class ConfigFileLoaderTest extends MockedTest 'test_2' => 2 ], 'config' => [ - 'test' => 'it' + 'test' => 'it', + ], + 'special_chars' => [ + 'special' => $specialChars, ]], $configCache2->getDataBySource(Cache::SOURCE_DATA)); } }