[BUG] v1.2.0 seems to produce incorrect diff
KevinWang15 opened this issue ยท 10 comments
This testcase:
func Test(t *testing.T) {
src := "a\na: a\na:\n a:\n a\n a: \"a\"\n a: a\n a: \"1\"\n a: 1\n -"
dst := "abcde: xxxxx"
dmp := New()
wSrc, wDst, warray := dmp.DiffLinesToRunes(src, dst)
diffs := dmp.DiffMainRunes(wSrc, wDst, false)
diffs = dmp.DiffCharsToLines(diffs, warray)
fmt.Printf("SRC:\n%s\n\nDST:\n%s\n\nDiff:\n%v", src, dst, diffs)
}
Will produce
SRC:
a
a: a
a:
a:
a
a: "a"
a: a
a: "1"
a: 1
-
DST:
abcde: xxxxx
Diff:
[{Equal a
} {Delete a: a
a:
a:
a
a: "a"
a: a
a: "1"
a: 1
} {Equal a
} {Delete }]
In v1.2.0, which is incorrect.
In v1.1.0, it produces the correct diff of
SRC:
a
a: a
a:
a:
a
a: "a"
a: a
a: "1"
a: 1
-
DST:
abcde: xxxxx
Diff:
[{Delete a
a: a
a:
a:
a
a: "a"
a: a
a: "1"
a: 1
-} {Insert abcde: xxxxx}]
I'm seeing this problem as well. I had to revert to 1.1.0
I also had this problem. All the examples I could find were producing garbage results until I found this issue and realised that 1.2.0
was the culprit. Switched to version 1.1.0
and all seems fine.
@sergi Please take a look when possible, as many other libraries are depending on this one, thanks!
This was broken with db1b095 by passing a array to diffLinesToStringsMunge
instead of a map.
Calling that function with multiple files, but passing the same array, now leads to duplicated lines for each file in the array, instead of re-using existing lines.
Any updates here?
I ran into this issue as well. Reverting to 1.1.0 fixes it.
go mod edit -exclude=github.com/sergi/go-diff@v1.2.0
may be helpful to prevent an accidental upgrade with go mod tidy
or go get -u ./...
.