corka149 / jsonpatch

A implementation of RFC 6902 in pure Elixir.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Merging maps with nil values creates add operations

stuartc opened this issue · comments

Describe the bug
I'm merging two maps that have identical values (that are nil) and
when diffing an add operation is returned.

I believe the issue is when a nil value is encountered it is treated as if the key doesn't exist on the destination side.

To Reproduce
Steps to reproduce the behavior:

source = %{"id" => nil}
destination = %{"id" => nil}
# => [%Jsonpatch.Operation.Add{path: "/id", value: nil}]

Expected behavior

There should be no diffs.

Hey @stuartc and thx for the detailed issue and PR. Indeed this looks wrong.

Actually the same occurs for lists.

iex(1)> Jsonpatch.diff [nil], [nil]
[%Jsonpatch.Operation.Add{path: "/0", value: nil}]

Edit: Ah, I see you are already tackling this in your PR.