Skip to content
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

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

Open
edknittel opened this issue Sep 28, 2022 · 1 comment

Comments

@edknittel
Copy link

edknittel commented Sep 28, 2022

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
Copy link
Author

Looks like this issue was fixed in this commit but for some reason it's not made it to master 74a3040

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant