Open
Description
The following code panics when using PatchApply
func main() {
dmp := diffmatchpatch.New()
patches, _ := dmp.PatchFromText("@@ -1,2 +1,3 @@\n %E2%98%9E \n+r\n")
fmt.Println(dmp.PatchToText(patches))
s, _ := dmp.PatchApply(patches, "β π’π₯πππ₯ ")
fmt.Println(fmt.Sprintf("%q", s))
}
panic: runtime error: slice bounds out of range [:35] with length 33
goroutine 1 [running]:
github.com/sergi/go-diff/diffmatchpatch.(*DiffMatchPatch).PatchApply(0x14000109ef8, {0x14000078200?, 0x1, 0x1?}, {0x102d6650a, 0x19})
/Users/michael/go/pkg/mod/github.com/sergi/[email protected]/diffmatchpatch/patch.go:306 +0x998
main.main()
/Users/michael/code/playground/scratch/main.go:14 +0xf0
exit status 2
It looks like its finding the wrong start location here - https://github.com/sergi/go-diff/blob/master/diffmatchpatch/patch.go#L265
E.g: this prints 25...
func main() {
dmp := diffmatchpatch.New()
fmt.Println(dmp.MatchMain("\x01\x02\x03\x04β π’π₯πππ₯ \x01\x02\x03\x04", "β \x01\x02\x03\x04", 4))
}
Metadata
Metadata
Assignees
Labels
No labels