Skip to content

Support adding to null + less strict array bound check #22

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 5 additions & 2 deletions src/JsonPatch.php
Original file line number Diff line number Diff line change
Expand Up @@ -517,6 +517,10 @@ private static function do_op($doc, $op, $path, $parts, $value,
return $doc;
}

if (null === $doc && ($op == 'add' || $op == 'append')) {
$doc = [];
}

// at target
if (!is_array($doc))
{
Expand All @@ -534,8 +538,7 @@ private static function do_op($doc, $op, $path, $parts, $value,
{
// check range, if numeric
if (self::is_index($part) &&
($part < 0 || (($op == 'remove' && $part >= count($doc))
|| ($op != 'remove' && $part > count($doc)))))
($part < 0 || (($op == 'remove' && $part >= count($doc)))))
{
throw new JsonPatchException("Can't operate outside of array bounds");
}
Expand Down