Skip to content

Incorrect paths for Remove operation #76

@tg666

Description

@tg666

If multiple items are removed from an array, the individual changes have incorrect path.

<?php

use Swaggest\JsonDiff\JsonDiff;
use Swaggest\JsonDiff\JsonPatch;

$original = (object) [
    'letters' => ['A', 'B', 'C', 'D'],
];

$modified = (object) [
    'letters' => ['A', 'B'],
];

$jsonDiff = new JsonDiff(
    original: $original,
    new: $modified,
);

$changeset = JsonPatch::export($jsonDiff->getPatch());

var_dump($changeset);

The result (both changes have the path /letters/2):

array(2) {
  [0]=>
  object(stdClass)#802 (2) {
    ["op"]=>
    string(6) "remove"
    ["path"]=>
    string(10) "/letters/2"
  }
  [1]=>
  object(stdClass)#801 (2) {
    ["op"]=>
    string(6) "remove"
    ["path"]=>
    string(10) "/letters/2"
  }
}

Probably related to #70

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions