@@ -53,6 +53,31 @@ func TestMergePatchNilDoc(t *testing.T) {
5353 }
5454}
5555
56+ type arrayCases struct {
57+ original , patch , res string
58+ }
59+
60+ func TestMergePatchNilArray (t * testing.T ) {
61+
62+ cases := []arrayCases {
63+ {`{"a": [ {"b":"c"} ] }` , `{"a": [1]}` , `{"a": [1]}` },
64+ {`{"a": [ {"b":"c"} ] }` , `{"a": [null, 1]}` , `{"a": [null, 1]}` },
65+ {`["a",null]` , `[null]` , `[null]` },
66+ {`["a"]` , `[null]` , `[null]` },
67+ {`["a", "b"]` , `["a", null]` , `["a", null]` },
68+ {`{"a":["b"]}` , `{"a": ["b", null]}` , `{"a":["b", null]}` },
69+ {`{"a":[]}` , `{"a": ["b", null, null, "a"]}` , `{"a":["b", null, null, "a"]}` },
70+ }
71+
72+ for _ , c := range cases {
73+ act := mergePatch (c .original , c .patch )
74+
75+ if ! compareJSON (c .res , act ) {
76+ t .Errorf ("null values not preserved in array" )
77+ }
78+ }
79+ }
80+
5681func TestMergePatchRecursesIntoObjects (t * testing.T ) {
5782 doc := `{ "person": { "title": "hello", "age": 18 } }`
5883 pat := `{ "person": { "title": "goodbye" } }`
0 commit comments