benjamine / jsondiffpatch

Diff & patch JavaScript objects
MIT License
4.77k stars 464 forks source link

URIError: malformed URI #325

Closed AlabasterAxe closed 1 year ago

AlabasterAxe commented 1 year ago

I'm still trying to work through what diff generated this but I figured I'd file this and can add more information as I discover it.

It looks like when diffing long strings with json diff patch, googles diff match patch utility can throw this malformed URI error.

AlabasterAxe commented 1 year ago

For future reference if other people are experiencing this. This seems to have been caused by our application only attempting to remove a single character of an emoji when a user pressed backspace before an emoji

JulesLecuir commented 1 year ago

I do have the same problem with identical strings, also containing emojis. Will investigate asap.

AlabasterAxe commented 1 year ago

Are you sure they're identical? This error can happen if the emoji only differ by a single surrogate unicode character.

AlabasterAxe commented 1 year ago

For example these two emoji differ by only a single character: 👈 (0xD83D, 0xDC49) and 👌 (0xD83D, 0xDC4C)). So if you diff long strings containing them, the diff will contain a single emoji byte which will cause uri encode to fail.