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

bugfix when handling array #97

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

wenhoujx
Copy link

@wenhoujx wenhoujx commented Apr 6, 2021

there is a bug that all the operations in diffs are stateful in the sense that their operation depends on the operations before them.

The remove and add case breaks the diffs order b/c it removes and add to the end of diffs.

repro:

    @Test
    void testJsonPatchBug() throws JsonProcessingException, JsonPatchException {
        JsonNode config1 = YAML_MAPPER.readTree(""
                + "foo:\n"
                + "  - bar:\n"
                + "      - baz: a\n"
                + "      - baz: b\n"
                + "      - baz: c\n"
                + "  - bar:\n"
                + "      - baz: d\n");
        JsonNode config2 = YAML_MAPPER.readTree(""
                + "foo:\n"
                + "- bar:\n"
                + "  - baz: d\n"
                + "- bar:\n"
                + "  - baz: c\n"
                + "  - baz: b\n"
                + "  - baz: a\n");
        Assertions.assertThat(JsonDiff.asJsonPatch(config1, config2).apply(config1))
                .isEqualTo(config2);

    }

# test fails the actual config is : 
foo:
- bar:
  - baz: d
- bar:
  - baz: c
  - baz: c
  - baz: a

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

Successfully merging this pull request may close these issues.

1 participant