Skip to content
This repository has been archived by the owner on Aug 5, 2024. It is now read-only.

Diff breaks unicode characters for emojis #59

Open
orromis opened this issue Feb 28, 2019 · 5 comments · May be fixed by #69
Open

Diff breaks unicode characters for emojis #59

orromis opened this issue Feb 28, 2019 · 5 comments · May be fixed by #69

Comments

@orromis
Copy link

orromis commented Feb 28, 2019

I'm working message log in our app. We want to show diff of changes any user made on text posts. Those posts may include emoji characters but diff_match_patch replaces those characters with � character (but only if they changed in the text).

The behaviour can be reproduced here:
https://neil.fraser.name/software/diff_match_patch/demos/diff.html

Paste 😉and 😀into textareas and compute the diff.

Why is this happening?

@mcataford
Copy link

mcataford commented Mar 6, 2019

Looks like the diffing doesn't consider whether a character is non-ASCII and breaks unicode emojis in pieces if they are different but occupy the same space. That would result in some unknown character � after all is said and done. Assuming it's conversion related.

Looking into it out of curiosity.

@judofyr judofyr linked a pull request Jun 20, 2019 that will close this issue
@josephrocca
Copy link

josephrocca commented Aug 18, 2019

Looks like @yetanotherape has solved it for their PHP fork:

The two current attempts at solving it in this repo have both had complications:

@ndvbd
Copy link

ndvbd commented May 24, 2021

Any updates here?

@josephrocca
Copy link

josephrocca commented May 24, 2021

@ndvbd I ended up "solving" it by just escaping all the special unicode stuff with text = encodeURI(text) before saving the text (and using decodeURI(...) to undo it, of course). Bit of a hack but it works for my use case.

@dmsnell
Copy link

dmsnell commented May 25, 2021

Check out #80, as referenced above @ndvbd's comment. It should handle all the surrogate pairs properly.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants