You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
diff.Diff() with an empty value produces one blank line #22
I have a series of blobs to diff, each against the previous. The seed is an empty string. Diffing the first blob against that produces a diff with one "removed" line.
Hmm, yeah that is unfortunate. I think this would be too big of a behavior change for a minor version update, however.
The reason for this is that Diff is comparing lines from A to lines in B by splitting on \n, so there is no way to get Diff to compare against zero lines on one of its sides.
To help improve this situation, I've exported Render which can be used directly on the output of DiffChunks, so that you can control this behavior yourself. For example, you could make a helper like this:
For the moment, this is only exposed by github.com/kylelemons/godebug@master if you are using go modules; let me know if this works for you, and I can cut a new module release.
I also highly recommend the cmp package if you are comparing structures, as it actually does proper recursive descent instead of stringifying everything before running a string-based diff algorithm.
This was not a critical issue for me, so frankly I probably won't update or change what we're doing. I thought it was worth filing a bug, but it sounds like it's not something you want to "break" (though IMO that's debatable, but I admire the dedication to not breaking people :).
Thanks for a great and simple lib that (mostly) just works.
Activity
kylelemons commentedon Aug 24, 2019
Hmm, yeah that is unfortunate. I think this would be too big of a behavior change for a minor version update, however.
The reason for this is that Diff is comparing lines from A to lines in B by splitting on
\n, so there is no way to get Diff to compare against zero lines on one of its sides.To help improve this situation, I've exported Render which can be used directly on the output of DiffChunks, so that you can control this behavior yourself. For example, you could make a helper like this:
to get the behavior you're looking for.
For the moment, this is only exposed by
github.com/kylelemons/godebug@masterif you are using go modules; let me know if this works for you, and I can cut a new module release.I also highly recommend the
cmppackage if you are comparing structures, as it actually does proper recursive descent instead of stringifying everything before running a string-based diff algorithm.thockin commentedon Aug 30, 2019
This was not a critical issue for me, so frankly I probably won't update or change what we're doing. I thought it was worth filing a bug, but it sounds like it's not something you want to "break" (though IMO that's debatable, but I admire the dedication to not breaking people :).
Thanks for a great and simple lib that (mostly) just works.
fix: avoid spurious deleted line when diffing empty string
fix: do not produce spurious blank deleted line when diffing empty st…