1
0
Fork 0

Fix some more inconsistencies in json manipulation

pull/2897/head
Jordi Boggiano 2014-04-10 16:11:43 +02:00
parent d742ffca4f
commit 4392be4d29
2 changed files with 49 additions and 0 deletions

View File

@ -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"

View File

@ -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(