Storage: Properly escape and unescape names with operators

fixes #205
This commit is contained in:
Johannes Meyer 2019-02-28 10:41:52 +01:00
parent cad29d4d32
commit c5d3127303
2 changed files with 6 additions and 3 deletions

View file

@ -301,7 +301,7 @@ class LegacyConfigParser
}
$op = '&';
if (preg_match_all('~([\|\+&\!])~', $value, $m)) {
if (preg_match_all('~(?<!\\\\)([\|\+&\!])~', $value, $m)) {
$op = implode('', $m[1]);
for ($i = 1; $i < strlen($op); $i++) {
if ($op[$i] !== $op[$i - 1]) {
@ -328,8 +328,9 @@ class LegacyConfigParser
));
$node->setBpConfig($bp);
$cmps = preg_split('~\s*\\' . $op . '\s*~', $value, -1, PREG_SPLIT_NO_EMPTY);
$cmps = preg_split('~\s*(?<!\\\\)\\' . $op . '\s*~', $value, -1, PREG_SPLIT_NO_EMPTY);
foreach ($cmps as $val) {
$val = preg_replace('~(\\\\([\|\+&\!]))~', '$2', $val);
if (strpos($val, ';') !== false) {
if ($bp->hasNode($val)) {
$node->addChild($bp->getNode($val));

View file

@ -184,7 +184,9 @@ class LegacyConfigRenderer
{
$op = static::renderOperator($node);
$children = $node->getChildNames();
$str = implode(' ' . $op . ' ', $children);
$str = implode(' ' . $op . ' ', array_map(function ($val) {
return preg_replace('~([\|\+&\!])~', '\\\\$1', $val);
}, $children));
if ((count($children) < 2) && $op !== '&') {
return $op . ' ' . $str;