1
1
Fork 0

Escape single quotes and backslashes

This commit is contained in:
Philipp Holzer 2023-01-03 15:36:36 +01:00
parent 65d79d4c93
commit dd88d193b9
Signed by: nupplaPhil
GPG key ID: 24A7501396EB5432
3 changed files with 10 additions and 3 deletions

View file

@ -75,7 +75,7 @@ class ConfigFileTransformer
} elseif (is_numeric($value)) { } elseif (is_numeric($value)) {
$string .= $value . ","; $string .= $value . ",";
} else { } else {
$string .= sprintf('\'%s\',', $value); $string .= sprintf('\'%s\',', addcslashes($value, '\'\\'));
} }
$string .= PHP_EOL; $string .= PHP_EOL;

View file

@ -34,5 +34,6 @@ return [
'theme' => 'frio', 'theme' => 'frio',
'int' => 23, 'int' => 23,
'float' => 2.5, 'float' => 2.5,
'with special chars' => 'I can\'t follow this "$&§%"$%§$%&\'[),',
], ],
]; ];

View file

@ -28,7 +28,7 @@ use Friendica\Test\Util\VFSTrait;
use Friendica\Core\Config\Util\ConfigFileManager; use Friendica\Core\Config\Util\ConfigFileManager;
use org\bovigo\vfs\vfsStream; use org\bovigo\vfs\vfsStream;
class ConfigFileLoaderTest extends MockedTest class ConfigFileManagerTest extends MockedTest
{ {
use VFSTrait; use VFSTrait;
@ -407,10 +407,13 @@ class ConfigFileLoaderTest extends MockedTest
$configFileLoader->setupCache($configCache); $configFileLoader->setupCache($configCache);
$specialChars = '!"§$%&/()(/&%$\'><?$a,;:[]}{}\\';
// overwrite some data and save it back to the config file // overwrite some data and save it back to the config file
$configCache->set('system', 'test', 'it', Cache::SOURCE_DATA); $configCache->set('system', 'test', 'it', Cache::SOURCE_DATA);
$configCache->set('config', 'test', 'it', Cache::SOURCE_DATA); $configCache->set('config', 'test', 'it', Cache::SOURCE_DATA);
$configCache->set('system', 'test_2', 2, Cache::SOURCE_DATA); $configCache->set('system', 'test_2', 2, Cache::SOURCE_DATA);
$configCache->set('special_chars', 'special', $specialChars, Cache::SOURCE_DATA);
$configFileLoader->saveData($configCache); $configFileLoader->saveData($configCache);
// Reload the configCache with the new values // Reload the configCache with the new values
@ -424,7 +427,10 @@ class ConfigFileLoaderTest extends MockedTest
'test_2' => 2 'test_2' => 2
], ],
'config' => [ 'config' => [
'test' => 'it' 'test' => 'it',
],
'special_chars' => [
'special' => $specialChars,
]], $configCache2->getDataBySource(Cache::SOURCE_DATA)); ]], $configCache2->getDataBySource(Cache::SOURCE_DATA));
} }
} }