@@ -167,23 +167,30 @@ func readPatchDiffElement(patch []patchElement) (DiffElement, []patchElement, er
167
167
var err error
168
168
switch p .Op {
169
169
case "test" :
170
+ // Read path.
170
171
d .Path , err = readPointer (p .Path )
171
172
if err != nil {
172
173
return d , nil , err
173
174
}
174
- old , err := NewJsonNode (p .Value )
175
+ // Read value to test and remove.
176
+ testValue , err := NewJsonNode (p .Value )
175
177
if err != nil {
176
178
return d , nil , err
177
179
}
178
- d .OldValues = []JsonNode {old }
180
+ d .OldValues = []JsonNode {testValue }
179
181
patch = patch [1 :]
182
+ // Validate test and remove are paired because jd remove is strict.
180
183
if len (patch ) == 0 || patch [0 ].Op != "remove" {
181
184
return d , nil , fmt .Errorf ("JSON Patch test op must be followed by a remove op." )
182
185
}
183
186
if patch [0 ].Path != p .Path {
184
187
return d , nil , fmt .Errorf ("JSON Patch remove op must have the same path as test op." )
185
188
}
186
- if patch [0 ].Value != p .Value {
189
+ removeValue , err := NewJsonNode (patch [0 ].Value )
190
+ if err != nil {
191
+ return d , nil , err
192
+ }
193
+ if ! testValue .Equals (removeValue ) {
187
194
return d , nil , fmt .Errorf ("JSON Patch remove op must have the same value as test op." )
188
195
}
189
196
return d , patch [1 :], nil
@@ -192,11 +199,11 @@ func readPatchDiffElement(patch []patchElement) (DiffElement, []patchElement, er
192
199
if err != nil {
193
200
return d , nil , err
194
201
}
195
- new , err := NewJsonNode (p .Value )
202
+ addValue , err := NewJsonNode (p .Value )
196
203
if err != nil {
197
204
return d , nil , err
198
205
}
199
- d .NewValues = []JsonNode {new }
206
+ d .NewValues = []JsonNode {addValue }
200
207
return d , patch [1 :], nil
201
208
default :
202
209
return d , nil , fmt .Errorf ("Invalid JSON Patch. Must be test/remove or add ops." )
0 commit comments