Skip to content

Library throws "URI malformed" error when creating patch with emojisΒ #22

Open
@laurent22

Description

@laurent22

The following code:

const DiffMatchPatch = require('diff-match-patch');
const dmp = new DiffMatchPatch();

const patchText = dmp.patch_toText(dmp.patch_make('', 'πŸ‘¨β€πŸ¦° πŸ‘¨πŸΏβ€πŸ¦° πŸ‘¨β€πŸ¦± πŸ‘¨πŸΏβ€πŸ¦± πŸ¦ΉπŸΏβ€β™‚οΈ'));
const patchObj = dmp.patch_fromText(patchText);
const [patchedText] = dmp.patch_apply(patchObj, '');
dmp.patch_toText(dmp.patch_make(patchedText, 'πŸ‘Ύ πŸ™‡ πŸ’ πŸ™… πŸ™† πŸ™‹ πŸ™Ž πŸ™'));

Will throw an error "URI Malformed" at this line. That's often the problem when using encodeURI on arbitrary data (the md5 package has the same problem) but in that case as far as I can see the inputs are valid UTF-8.

I think either patch_make or patch_apply generates invalid text.

But also I'm wondering why is encodeURI needed in this lib? Wouldn't a simple escape/unescape of specific reserved characters be enough?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions