File tree Expand file tree Collapse file tree 2 files changed +16
-3
lines changed
Expand file tree Collapse file tree 2 files changed +16
-3
lines changed Original file line number Diff line number Diff line change @@ -175,7 +175,7 @@ defmodule Jsonpatch do
175175 acc =
176176 case get ( source , key ) do
177177 # Key is not present in source
178- nil ->
178+ :__jsonpatch_lib__missing_value__ ->
179179 [ % Add { path: current_path , value: val } | acc ]
180180
181181 # Source has a different value but both (destination and source) value are lists or a maps
@@ -209,11 +209,11 @@ defmodule Jsonpatch do
209209
210210 # Unified access to lists or maps
211211 defp get ( source , key ) when is_list ( source ) do
212- Enum . at ( source , key )
212+ Enum . at ( source , key , :__jsonpatch_lib__missing_value__ )
213213 end
214214
215215 defp get ( source , key ) when is_map ( source ) do
216- Map . get ( source , key )
216+ Map . get ( source , key , :__jsonpatch_lib__missing_value__ )
217217 end
218218
219219 # Escape `/` to `~1 and `~` to `~0`.
Original file line number Diff line number Diff line change @@ -50,6 +50,19 @@ defmodule JsonpatchTest do
5050 assert [ % Remove { path: "/baz" } ] = patch
5151 end
5252
53+ test "Create no diff on unchanged nil object value" do
54+ source = % { "id" => nil }
55+ destination = % { "id" => nil }
56+ assert [ ] = Jsonpatch . diff ( source , destination )
57+ end
58+
59+ test "Create no diff on unchanged array value" do
60+ source = [ nil ]
61+ destination = [ nil ]
62+
63+ assert [ ] = Jsonpatch . diff ( source , destination )
64+ end
65+
5366 test "Create no diff on unexpected input" do
5467 assert [ ] = Jsonpatch . diff ( "unexpected" , 1 )
5568 end
You can’t perform that action at this time.
0 commit comments