Skip to content

Commit

Permalink
Fix inputs with empty keys
Browse files Browse the repository at this point in the history
Signed-off-by: John Howard <howardjohn@google.com>
  • Loading branch information
howardjohn committed May 16, 2023
1 parent 1f7eb13 commit 2c05a51
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 3 deletions.
3 changes: 0 additions & 3 deletions v2/jsonpatch.go
Original file line number Diff line number Diff line change
Expand Up @@ -149,9 +149,6 @@ func makePath(path string, newPart interface{}) string {
if path == "" {
return "/" + key
}
if strings.HasSuffix(path, "/") {
return path + key
}
return path + "/" + key
}

Expand Down
7 changes: 7 additions & 0 deletions v2/jsonpatch_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -836,6 +836,11 @@ var (
}`
)

var (
emptyKeyA = `{"":[0]}`
emptyKeyB = `{"":[]}`
)

func TestCreatePatch(t *testing.T) {
cases := []struct {
name string
Expand Down Expand Up @@ -881,6 +886,8 @@ func TestCreatePatch(t *testing.T) {
{"Array at root", `[{"asdf":"qwerty"}]`, `[{"asdf":"bla"},{"asdf":"zzz"}]`},
{"Empty array at root", `[]`, `[{"asdf":"bla"},{"asdf":"zzz"}]`},
{"Null Key uses replace operation", nullKeyA, nullKeyB},
// empty key
{"Empty key", emptyKeyA, emptyKeyB},
}

for _, c := range cases {
Expand Down

0 comments on commit 2c05a51

Please sign in to comment.