1
0
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)) {
$string .= $value . ",";
} else {
$string .= sprintf('\'%s\',', $value);
$string .= sprintf('\'%s\',', addcslashes($value, '\'\\'));
}
$string .= PHP_EOL;

View file

@ -34,5 +34,6 @@ return [
'theme' => 'frio',
'int' => 23,
'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 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 = '!"§$%&/()(/&%$\'><?$a,;:[]}{}\\';
// overwrite some data and save it back to the config file
$configCache->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));
}
}