diff --git a/diffmatchpatch/diff.go b/diffmatchpatch/diff.go index f70d6f3..16b03f2 100644 --- a/diffmatchpatch/diff.go +++ b/diffmatchpatch/diff.go @@ -500,8 +500,8 @@ func commonSuffixLength(text1, text2 []rune) int { // DiffCommonOverlap determines if the suffix of one string is the prefix of another. func (dmp *DiffMatchPatch) DiffCommonOverlap(text1 string, text2 string) int { // Cache the text lengths to prevent multiple calls. - text1Length := len(text1) - text2Length := len(text2) + text1Length := len([]rune(text1)) + text2Length := len([]rune(text2)) // Eliminate the null case. if text1Length == 0 || text2Length == 0 { return 0 diff --git a/diffmatchpatch/diff_test.go b/diffmatchpatch/diff_test.go index 6c159cb..e3689ae 100644 --- a/diffmatchpatch/diff_test.go +++ b/diffmatchpatch/diff_test.go @@ -845,6 +845,18 @@ func TestDiffCleanupSemantic(t *testing.T) { {DiffInsert, "a new hope"}, }, }, + { + "panic", + []Diff{ + {DiffInsert, "킬러 인 "}, + {DiffEqual, "리커버리"}, + {DiffDelete, " 보이즈"}, + }, + []Diff{ + {DiffDelete, "리커버리 보이즈"}, + {DiffInsert, "킬러 인 리커버리"}, + }, + }, } { actual := dmp.DiffCleanupSemantic(tc.Diffs) assert.Equal(t, tc.Expected, actual, fmt.Sprintf("Test case #%d, %s", i, tc.Name))