diff --git a/util/diff/diff.go b/util/diff/diff.go index 94d8e81c..58848414 100644 --- a/util/diff/diff.go +++ b/util/diff/diff.go @@ -239,9 +239,9 @@ func (o *operations) patch(old map[string]interface{}) (now map[string]interface case "change": if txt, ok := obj.Get(path...).Data().(string); ok { dmp := diffmatchpatch.New() - if dif, err := dmp.DiffFromDelta(txt, v.value.(string)); err == nil { - str := dmp.DiffText2(dif) - obj.Set(str, path...) + if pch, err := dmp.PatchFromText(v.value.(string)); err == nil { + txt, _ := dmp.PatchApply(pch, txt) + obj.Set(txt, path...) } } } @@ -256,9 +256,9 @@ func (o *operations) text(old, now string, path string) { dmp := diffmatchpatch.New() - dif := dmp.DiffMain(old, now, false) + pch := dmp.PatchMake(old, now) - txt := dmp.DiffToDelta(dif) + txt := dmp.PatchToText(pch) o.op("change", "", path, old, txt) diff --git a/util/diff/diff_test.go b/util/diff/diff_test.go index 2c1b3fb2..28e1e7b1 100644 --- a/util/diff/diff_test.go +++ b/util/diff/diff_test.go @@ -109,12 +109,12 @@ var chg = []interface{}{ map[string]interface{}{ "op": "change", "path": "/name/first", - "value": "=1\t+obie", + "value": "@@ -1 +1,5 @@\n T\n+obie\n", }, map[string]interface{}{ "op": "change", "path": "/name/last", - "value": "=1\t+organ\t=2\t+itchcock", + "value": "@@ -1,3 +1,16 @@\n M\n- H\n+organ Hitchcock\n", }, }