kbadk / json0-ot-diff

Finds differences between two JSON object and generates operational transformation (OT) operations for transforming the first object into the second according to the JSON0 OT Type.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

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

tioken opened this issue · 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?

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.