Fix remove command not working with escaped slashes (e.g. foo\/bar), fixes #8249
parent
1a391b572c
commit
14f2a6dd9a
|
@ -326,9 +326,10 @@ class JsonManipulator
|
||||||
}
|
}
|
||||||
|
|
||||||
// try and find a match for the subkey
|
// try and find a match for the subkey
|
||||||
if ($this->pregMatch('{"'.preg_quote($name).'"\s*:}i', $children)) {
|
$keyRegex = str_replace('/', '\\\\?/', preg_quote($name));
|
||||||
|
if ($this->pregMatch('{"'.$keyRegex.'"\s*:}i', $children)) {
|
||||||
// find best match for the value of "name"
|
// find best match for the value of "name"
|
||||||
if (preg_match_all('{'.self::$DEFINES.'"'.preg_quote($name).'"\s*:\s*(?:(?&json))}x', $children, $matches)) {
|
if (preg_match_all('{'.self::$DEFINES.'"'.$keyRegex.'"\s*:\s*(?:(?&json))}x', $children, $matches)) {
|
||||||
$bestMatch = '';
|
$bestMatch = '';
|
||||||
foreach ($matches[0] as $match) {
|
foreach ($matches[0] as $match) {
|
||||||
if (strlen($bestMatch) < strlen($match)) {
|
if (strlen($bestMatch) < strlen($match)) {
|
||||||
|
|
|
@ -1448,6 +1448,22 @@ class JsonManipulatorTest extends TestCase
|
||||||
"repositories": {
|
"repositories": {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
',
|
||||||
|
),
|
||||||
|
'works on simple ones escaped slash' => array(
|
||||||
|
'{
|
||||||
|
"repositories": {
|
||||||
|
"foo\/bar": {
|
||||||
|
"bar": "baz"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}',
|
||||||
|
'foo/bar',
|
||||||
|
true,
|
||||||
|
'{
|
||||||
|
"repositories": {
|
||||||
|
}
|
||||||
|
}
|
||||||
',
|
',
|
||||||
),
|
),
|
||||||
'works on simple ones middle' => array(
|
'works on simple ones middle' => array(
|
||||||
|
|
Loading…
Reference in New Issue