json0-ot-diff icon indicating copy to clipboard operation
json0-ot-diff copied to clipboard

If the string contains Unicode Emoji, the index will be misaligned.

Open tioken opened this issue 3 years ago • 1 comments

Hello, thanks for this useful library!

I'd like to report a bug that I encountered while using it.

 json0diff(['Hello'], ['🤗Hello🤗'], DiffMatchPatch, json1, textUnicode);
// Outputs => [0,{"es":["🤗",6,"🤗"]}]

When this is passed to the apply method of json1, an error message Error: The op is too long for this document will be displayed.

It seems that text-unicode treats emoji as a single character. changing the index from 6 to 5 works fine.

 [0,{"es":["🤗",5,"🤗"]}]

If it is possible, could you please fix it?

tioken avatar Dec 10 '21 05:12 tioken

Aha! This is actually a flaw in the underlying JSON0 implementation. It is fixed in JSON1 - see https://github.com/ottypes/json1#interoperability-with-json0

Because of this, I'm not sure if it's even possible to fix this issue in this library.

However, a failing unit test would be a great first step.

curran avatar Dec 10 '21 12:12 curran