Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[BUG] v1.2.0 seems to produce incorrect diff #123

Open
KevinWang15 opened this issue Jul 6, 2021 · 10 comments
Open

[BUG] v1.2.0 seems to produce incorrect diff #123

KevinWang15 opened this issue Jul 6, 2021 · 10 comments

Comments

@KevinWang15
Copy link

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}]
@eastlondoner
Copy link

I'm seeing this problem as well. I had to revert to 1.1.0

@peter-evans
Copy link

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.

@KevinWang15
Copy link
Author

@sergi Please take a look when possible, as many other libraries are depending on this one, thanks!

@schrej
Copy link

schrej commented Nov 16, 2021

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.

@aymanbagabas
Copy link

Any updates here?

@huguesalary
Copy link

I ran into this issue as well. Reverting to 1.1.0 fixes it.

@uhthomas
Copy link

go mod edit -exclude=github.com/sergi/[email protected]

may be helpful to prevent an accidental upgrade with go mod tidy or go get -u ./....

@kdarkhan
Copy link
Contributor

I created #136 which should fix the issue.

@AriehSchneier
Copy link

@sergi Any chance of merging #120 or #136 to fix this? This library is currently giving incorrect results.

@kdarkhan
Copy link
Contributor

kdarkhan commented Aug 3, 2023

#136 was merged yesterday, so this should be resolved now.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

9 participants