Fix some more inconsistencies in json manipulation
parent
d742ffca4f
commit
4392be4d29
|
@ -204,6 +204,11 @@ class JsonManipulator
|
||||||
list($name, $subName) = explode('.', $name, 2);
|
list($name, $subName) = explode('.', $name, 2);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// no node to remove
|
||||||
|
if (!isset($decoded[$mainNode][$name]) || ($subName && !isset($decoded[$mainNode][$name][$subName]))) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
// 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)) {
|
if ($this->pregMatch('{"'.preg_quote($name).'"\s*:}i', $children)) {
|
||||||
// find best match for the value of "name"
|
// find best match for the value of "name"
|
||||||
|
|
|
@ -368,6 +368,50 @@ class JsonManipulatorTest extends \PHPUnit_Framework_TestCase
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
'
|
||||||
|
),
|
||||||
|
'works on child having unmatched name' => array(
|
||||||
|
'{
|
||||||
|
"repositories": {
|
||||||
|
"baz": {
|
||||||
|
"foo": "bar",
|
||||||
|
"bar": "baz"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}',
|
||||||
|
'bar',
|
||||||
|
true,
|
||||||
|
'{
|
||||||
|
"repositories": {
|
||||||
|
"baz": {
|
||||||
|
"foo": "bar",
|
||||||
|
"bar": "baz"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
'
|
||||||
|
),
|
||||||
|
'works on child having duplicate name' => array(
|
||||||
|
'{
|
||||||
|
"repositories": {
|
||||||
|
"foo": {
|
||||||
|
"baz": "qux"
|
||||||
|
},
|
||||||
|
"baz": {
|
||||||
|
"foo": "bar",
|
||||||
|
"bar": "baz"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}',
|
||||||
|
'baz',
|
||||||
|
true,
|
||||||
|
'{
|
||||||
|
"repositories": {
|
||||||
|
"foo": {
|
||||||
|
"baz": "qux"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
'
|
'
|
||||||
),
|
),
|
||||||
'works on empty repos' => array(
|
'works on empty repos' => array(
|
||||||
|
|
Loading…
Reference in New Issue