1
0
Fork 0

Fix remove command not working with escaped slashes (e.g. foo\/bar), fixes #8249

pull/8252/head
Jordi Boggiano 2019-07-30 09:48:49 +02:00
parent 1a391b572c
commit 14f2a6dd9a
No known key found for this signature in database
GPG Key ID: 7BBD42C429EC80BC
2 changed files with 19 additions and 2 deletions

View File

@ -326,9 +326,10 @@ class JsonManipulator
}
// 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"
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 = '';
foreach ($matches[0] as $match) {
if (strlen($bestMatch) < strlen($match)) {

View File

@ -1448,6 +1448,22 @@ class JsonManipulatorTest extends TestCase
"repositories": {
}
}
',
),
'works on simple ones escaped slash' => array(
'{
"repositories": {
"foo\/bar": {
"bar": "baz"
}
}
}',
'foo/bar',
true,
'{
"repositories": {
}
}
',
),
'works on simple ones middle' => array(