Skip to content
This repository has been archived by the owner on Jul 23, 2019. It is now read-only.

Minified lib has broken RegExps #642

Closed
klasjersevi opened this issue Feb 15, 2019 · 7 comments
Closed

Minified lib has broken RegExps #642

klasjersevi opened this issue Feb 15, 2019 · 7 comments

Comments

@klasjersevi
Copy link

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
Copy link
Contributor

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

@klasjersevi
Copy link
Author

klasjersevi commented Feb 18, 2019

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
Copy link

Rosey commented Mar 6, 2019

I'm also experiencing this, thanks for making the issue 👍 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
Copy link
Contributor

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

@Rosey
Copy link

Rosey commented Mar 11, 2019

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
Copy link

Rosey commented Mar 11, 2019

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
Copy link
Contributor

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

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants