Ionaru / easy-markdown-editor

EasyMDE: A simple, beautiful, and embeddable JavaScript Markdown editor. Delightful editing for beginners and experts alike. Features built-in autosaving and spell checking.
https://stackblitz.com/edit/easymde
MIT License
2.38k stars 314 forks source link

"invalid group specifier name" using Safari #478

Closed donv closed 2 years ago

donv commented 2 years ago

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?

Ionaru commented 2 years ago

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?

donv commented 2 years ago

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

start = start.replace(/(.*)\[/, '$1');
Ionaru commented 2 years ago

There is a difference between the two:

image

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

m-thielen commented 2 years ago

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

/(.*)[^!]\[/
Ionaru commented 2 years ago

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.