curran / curran/google-diff-match-patch

Javascript version doesn't handle astral code points correctly

Open
#106 0 comments 0 reactions 0 assignees View on GitHub
auto-migrated Priority-Medium Type-Defect
Dominant language
Python
Stars
17
Forks
2
PR merge metrics
No merged PRs in 30d

Description

```
What steps will reproduce the problem?

var dmp = new diffMatchPatch();

var str1 = ">>> \ud83d\ude4b <<<";
var str2 = ">>> \ud83d\ude4c <<<";

var diffs = dmp.diff_main(str1, str2);
console.log("diff = " + JSON.stringify(diffs));

What is the expected output? What do you see instead?

Expected: diff = [[0,">>> "],[-1,"🙋 "],[1,"🙌 "],[0," <<<"]]
Actual: diff = [[0,">>> �"],[-1,"�"],[1,"�"],[0," <<<"]]

Expanded, in case there is a loss of fidelity in this issue posting:

Expected: diff = [[0,">>> "],[-1,"\ud83d\ude4b"],[1,"\ud83d\ude4c"],[0," <<<"]]
Actual: diff = [[0,">>> \ud83d"],[-1,"\ude4b"],[1,"\ude4c"],[0," <<<"]]

The diff is split *between* the surrogate characters of the astral code point.
Note that str1 and str2 share a common high surrogate.

What version of the product are you using? On what operating system?

1.0.0, on OSX

Please provide any additional information below.

```

Original issue reported on code.google.com by `keit...@rivaliq.com` on 1 May 2015 at 2:59

Contributor guide

No contributing guide indexed for this repository

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.