joypixels / emojione

[Archived] The world's largest independent emoji font. Maintained at https://github.com/joypixels/emoji-toolkit.
https://www.joypixels.com
Other
4.46k stars 536 forks source link

Minified lib has broken RegExps #642

Closed klasjersevi closed 5 years ago

klasjersevi commented 5 years ago

The minified (uglified) js-file is broken because of invalid RegExps. The escaping for ns.regShortNames, ns.regAscii and ns.regUnicode is stripped and therefore they become invalid.

caseyahenson commented 5 years ago

@klaslundberg can you provide some more details about where you see these error out? I'm not able to recreate the issue.

klasjersevi commented 5 years ago

Everything works fine when I use the uncompressed file. When I use the minified the console shows a very long message beginning with:

Uncaught SyntaxError: Invalid regular expression: /<object[^>]*>.*?</object>|<span[^>]*>.*?</span>|<(?:object|embed|svg|img|div|span|p|a)[^>]*>|...

If I compare the regUnicode in the minified and the uncompressed file, the backslashes are no longer escaped in the string, which shows on the end tag for object and span.

// uncompressed: <\/object>
ns.regUnicode = new RegExp("<object[^>]*>.*?<\/object>|<span[^>]*>.*?<\/span>|<(?:object|embed|svg|img|div|span|p|a)[^>]*>|("+ns.unicodeRegexp+")", "gi");

// minified: </object>
a.regUnicode=new RegExp("<object[^>]*>.*?</object>|<span[^>]*>.*?</span>|<(?:object|embed|svg|img|div|span|p|a)[^>]*>|("+a.unicodeRegexp+")","gi")
Rosey commented 5 years ago

I'm also experiencing this, thanks for making the issue :+1: thought I was going crazy.

I'm not seeing an error though, interestingly, the regular expression just doesn't "work". Like if I call emojione.regUnicode.test('😉') it returns false on the minified version but true on the non-minified version.

So perhaps whatever I am seeing is slightly different 😞

caseyahenson commented 5 years ago

Thanks for the clarification, I'll get this fixed up for our next release.

Rosey commented 5 years ago

FWIW the issue that I mentioned was resolved by making a change on my end, so perhaps not directly related to emojione's js. Setting ascii_only: true on webpack's uglifyjs settings solved the issue for me. Be nice to not have to do that because I think it makes files slightly larger but I don't know if there's any way around that, seems like it's probably just the way it has to be 🙂

Rosey commented 5 years ago

I'm a bit confused though about the regular expression in general, I guess this isn't documented as part of the emojione js api but I'm finding it handy so have been using it 🙃 perhaps that's where my problem is 😛 .

Anyway -

emojione.regUnicode.test returns true in cases I thought would be false. Eg emojione.regUnicode.test("*") === true and emojione.regUnicode.test("<p>") === true as well. Is that to be expected? I thought it would only return true in cases where it's... an emoji. 🤔

caseyahenson commented 5 years ago

This is fixed in the 5.0 release https://github.com/joypixels/emoji-toolkit/releases/tag/5.0.0.