json-diff icon indicating copy to clipboard operation
json-diff copied to clipboard

getPatch with REARRANGE_ARRAYS is not returning the correct paths when items are removed from an array

Open edknittel opened this issue 3 years ago • 1 comments

TEST

$previous = ['Apples', 'Oranges', 'Bananas', 'Grapes'];
$current = ['Apples', 'Grapes'];
$JsonDiff = new JsonDiff($previous, $current, JsonDiff::REARRANGE_ARRAYS);
$patch = json_decode(json_encode($JsonDiff->getPatch()), true) ?: [];
print_r($patch);

EXPECTED RESULT

When the [1] and [2] position items in the array are successfully removed the patch accurately reflects this Array ( [0] => Array ( [op] => remove [path] => /1 ) [1] => Array ( [op] => remove [path] => /2) )

ACTUAL RESULT

When [1] and [2] position items in the array are successfully removed the patch only reflects the first item and it's repeated twice. There is no reference to the second item anywhere in the patch response Array ( [0] => Array ( [op] => remove [path] => /1 ) [1] => Array ( [op] => remove [path] => /1) )

edknittel avatar Sep 28 '22 01:09 edknittel

Looks like this issue was fixed in this commit but for some reason it's not made it to master https://github.com/swaggest/json-diff/commit/74a30409254895d216ab27d10bba166558604a3d

edknittel avatar Sep 28 '22 04:09 edknittel