Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 33 additions & 0 deletions Gopkg.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

38 changes: 38 additions & 0 deletions Gopkg.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
# Gopkg.toml example
#
# Refer to https://github.com/golang/dep/blob/master/docs/Gopkg.toml.md
# for detailed Gopkg.toml documentation.
#
# required = ["github.com/user/thing/cmd/thing"]
# ignored = ["github.com/user/project/pkgX", "bitbucket.org/user/project/pkgA/pkgY"]
#
# [[constraint]]
# name = "github.com/user/project"
# version = "1.0.0"
#
# [[constraint]]
# name = "github.com/user/project2"
# branch = "dev"
# source = "github.com/myfork/project2"
#
# [[override]]
# name = "github.com/x/y"
# version = "2.4.0"
#
# [prune]
# non-go = false
# go-tests = true
# unused-packages = true


[[constraint]]
name = "github.com/evanphx/json-patch"
version = "3.0.0"

[[constraint]]
name = "github.com/stretchr/testify"
version = "1.2.1"

[prune]
go-tests = true
unused-packages = true
37 changes: 21 additions & 16 deletions jsonpatch.go
Original file line number Diff line number Diff line change
Expand Up @@ -83,12 +83,12 @@ func matchesValue(av, bv interface{}) bool {
return true
}
case float64:
bt, ok := bv.(float64)
bt, ok := bv.(float64)
if ok && bt == at {
return true
}
case bool:
bt, ok := bv.(bool)
bt, ok := bv.(bool)
if ok && bt == at {
return true
}
Expand Down Expand Up @@ -183,9 +183,18 @@ func diff(a, b map[string]interface{}, path string, patch []Operation) ([]Operat
}

func handleValues(av, bv interface{}, p string, patch []Operation) ([]Operation, error) {
// If types have changed, replace completely
if reflect.TypeOf(av) != reflect.TypeOf(bv) {
return append(patch, NewPatch("replace", p, bv)), nil
{
at := reflect.TypeOf(av)
bt := reflect.TypeOf(bv)
if at == nil && bt == nil {
// do nothing
return patch, nil
} else if at == nil && bt != nil {
return append(patch, NewPatch("add", p, bv)), nil
} else if at != bt {
// If types have changed, replace completely (preserves null in destination)
return append(patch, NewPatch("replace", p, bv)), nil
}
}

var err error
Expand Down Expand Up @@ -220,13 +229,6 @@ func handleValues(av, bv interface{}, p string, patch []Operation) ([]Operation,
}
}
}
case nil:
switch bv.(type) {
case nil:
// Both nil, fine.
default:
patch = append(patch, NewPatch("add", p, bv))
}
default:
panic(fmt.Sprintf("Unknown type:%T ", av))
}
Expand Down Expand Up @@ -309,18 +311,21 @@ func min(x int, y int) int {

func backtrace(s, t []interface{}, p string, i int, j int, matrix [][]int) []Operation {
if i > 0 && matrix[i-1][j]+1 == matrix[i][j] {
return append(backtrace(s, t, p, i-1, j, matrix), NewPatch("remove", makePath(p, i-1), nil))
op := NewPatch("remove", makePath(p, i-1), nil)
return append([]Operation{op}, backtrace(s, t, p, i-1, j, matrix)...)
}
if j > 0 && matrix[i][j-1]+1 == matrix[i][j] {
return append(backtrace(s, t, p, i, j-1, matrix), NewPatch("add", makePath(p, i), t[j-1]))
op := NewPatch("add", makePath(p, i), t[j-1])
return append([]Operation{op}, backtrace(s, t, p, i, j-1, matrix)...)
}
if i > 0 && j > 0 && matrix[i-1][j-1]+1 == matrix[i][j] {
if isBasicType(s[0]) {
return append(backtrace(s, t, p, i-1, j-1, matrix), NewPatch("replace", makePath(p, i-1), t[j-1]))
op := NewPatch("replace", makePath(p, i-1), t[j-1])
return append([]Operation{op}, backtrace(s, t, p, i-1, j-1, matrix)...)
}

p2, _ := handleValues(s[j-1], t[j-1], makePath(p, i-1), []Operation{})
return append(backtrace(s, t, p, i-1, j-1, matrix), p2...)
return append(p2, backtrace(s, t, p, i-1, j-1, matrix)...)
}
if i > 0 && j > 0 && matrix[i-1][j-1] == matrix[i][j] {
return backtrace(s, t, p, i-1, j-1, matrix)
Expand Down
68 changes: 0 additions & 68 deletions jsonpatch_array_test.go

This file was deleted.

89 changes: 0 additions & 89 deletions jsonpatch_complex_test.go

This file was deleted.

49 changes: 0 additions & 49 deletions jsonpatch_geojson_test.go

This file was deleted.

Loading