File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 1+ # 1.0.1 (provisional)
2+ - Escape remaining keys before comparing them to the (already escaped) keys from earlier in the diffing process when determining Remove operations
3+
14# 1.0.0
25- Allow lists at top level of Jsonpatch.apply_patch
36- Fix error message when updating a non existing key in list
Original file line number Diff line number Diff line change @@ -160,7 +160,7 @@ defmodule Jsonpatch do
160160 acc =
161161 source
162162 |> flat ( )
163- |> Stream . map ( fn { k , _ } -> k end )
163+ |> Stream . map ( fn { k , _ } -> escape ( k ) end )
164164 |> Stream . filter ( fn k -> k not in checked_keys end )
165165 |> Stream . map ( fn k -> % Remove { path: "#{ ancestor_path } /#{ k } " } end )
166166 |> Enum . reduce ( acc , fn r , acc -> [ r | acc ] end )
Original file line number Diff line number Diff line change @@ -107,7 +107,7 @@ defmodule JsonpatchTest do
107107 ] = patch
108108 end
109109
110- test "Create diff with escaped '~' and '/' in path" do
110+ test "Create diff with escaped '~' and '/' in path when adding " do
111111 source = % { }
112112 destination = % { "escape/me~now" => "somnevalue" }
113113
@@ -117,6 +117,25 @@ defmodule JsonpatchTest do
117117 actual_patch
118118 end
119119
120+ test "Create diff with escaped '~' and '/' in path when removing" do
121+ source = % { "escape/me~now" => "somnevalue" }
122+ destination = % { }
123+
124+ actual_patch = Jsonpatch . diff ( source , destination )
125+
126+ assert [ % Jsonpatch.Operation.Remove { path: "/escape~1me~0now" } ] = actual_patch
127+ end
128+
129+ test "Create diff with escaped '~' and '/' in path when replacing" do
130+ source = % { "escape/me~now" => "somnevalue" }
131+ destination = % { "escape/me~now" => "othervalue" }
132+
133+ actual_patch = Jsonpatch . diff ( source , destination )
134+
135+ assert [ % Jsonpatch.Operation.Replace { path: "/escape~1me~0now" , value: "othervalue" } ] =
136+ actual_patch
137+ end
138+
120139 test "Create diff with nested map with correct Add/Remove order" do
121140 source = % { "a" => [ % { "b" => [ ] } ] }
122141 target = % { "a" => [ % { "b" => [ % { "c" => 1 } , % { "d" => 2 } ] } ] }
You can’t perform that action at this time.
0 commit comments