easy-markdown-editor icon indicating copy to clipboard operation
easy-markdown-editor copied to clipboard

"invalid group specifier name" using Safari

Open donv opened this issue 3 years ago • 5 comments

Regular use that works in Chrome and Firefox fails with Safari. Just loading the library.

SyntaxError: Invalid regular expression: invalid group specifier name

This happens at the regex at

https://github.com/Ionaru/easy-markdown-editor/blob/4d065c361e685a8b896741aa89dbe109b5338500/src/js/easymde.js#L1291

It uses a negative look ahead. I cannot see why the negative look ahead is needed. Wouldn't it just work without it?

donv avatar Jun 20 '22 21:06 donv

Ah that's unfortunate, I incorrectly assumed Safari had compatibility but it seems to be the only large browser that does not... 😕

https://caniuse.com/js-regexp-lookbehind

Do you have any suggestions for a replacement regex that works?

Ionaru avatar Jun 20 '22 22:06 Ionaru

Regxs are tricky, but wouldn't just removing the negative lookahead work?

start = start.replace(/(.*)\[/, '$1');

donv avatar Jun 21 '22 15:06 donv

There is a difference between the two:

image

An image is now also seen as a link, which is not correct.

Ionaru avatar Jun 23 '22 12:06 Ionaru

I am not a regex guru at all, but would this work?

/(.*)[^!]\[/

m-thielen avatar Aug 05 '22 11:08 m-thielen

That looks promising! So far it's been good in all my tests. I'll do a few more and then implement the new pattern. :)

@m-thielen if you want to make a PR for it I'll accept that instead.

Ionaru avatar Aug 07 '22 00:08 Ionaru