Skip to content

Commit

Permalink
Fix: Stop splitting surrogate-pairs in diff-match-patch deltas
Browse files Browse the repository at this point in the history
See google/diff-match-patch#80

There have been certain cases where consecutive surrogate pairs crash
`diff-match-patch` when it's building the _delta string_. This is
because the diffing algorithm finds a common prefix up to and including
half of the surrogate pair match when three consecutive code points
share the same high surrogate.

```
// before - \ud83d\ude4b\ud83d\ue4b
// after  - \ud83d\ude4b\ud83d\ue4c\ud83d\ude4b
// deltas - eq \ud83d\ude4b\ud83d -> add \ude4c -> eq \ud83d \ude4b
```

This crashes when trying to encode the invalid sequence of UTF-16 code
units into `URIEncode`, which expects a valid Unicode string.

After the fix the delta groups are normalized to prevent this situation
and the `node-simperium` library should be able to process those
problematic changesets.
  • Loading branch information
dmsnell committed Nov 12, 2019
1 parent e3822e2 commit 9ecfe99
Show file tree
Hide file tree
Showing 4 changed files with 188 additions and 120 deletions.
4 changes: 4 additions & 0 deletions RELEASE-NOTES.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
# Changelog

## 1.0.2

- Update diff-match-patch to fix problem when encoding consecutive surrogate pairs

## 1.0.1

- Disconnect from existing socket connection when connecting [#90](https://github.com/Simperium/node-simperium/pull/90)
Expand Down
2 changes: 1 addition & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "simperium",
"version": "1.0.1",
"version": "1.0.2",
"description": "A simperium client for node.js",
"main": "./lib/simperium/index.js",
"repository": {
Expand Down
Loading

0 comments on commit 9ecfe99

Please sign in to comment.