corka149 / jsonpatch

A implementation of RFC 6902 in pure Elixir.
MIT License
43 stars 11 forks source link

Replacing whole document does not work #22

Closed norpan closed 8 months ago

norpan commented 9 months ago

Describe the bug According to the jsonpath tests, it should be possible to replace the whole document using the path "".

To Reproduce Jsonpatch.apply_patch([%{"op" => "replace", "path" => "", "value" => %{"baz" => "qux"}}], %{"foo" => "bar"})

Result

{:error,
 %Jsonpatch.Error{
   patch: %{"op" => "replace", "path" => "", "value" => %{"baz" => "qux"}},
   patch_index: 0,
   reason: {:invalid_path, ""}
 }}

Expected behavior {:ok, %{"baz" => "qux"}}

Additional context Latest tests can be found at https://github.com/json-patch/json-patch-tests/blob/master/tests.json

corka149 commented 8 months ago

Hey @norpan , thx for submitting the issue. That revealed some edge cases.

norpan commented 8 months ago

Thanks for the quick reply and fix!