Closed klasjersevi closed 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.
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")
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 😞
Thanks for the clarification, I'll get this fixed up for our next release.
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 🙂
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. 🤔
This is fixed in the 5.0 release https://github.com/joypixels/emoji-toolkit/releases/tag/5.0.0.
The minified (uglified) js-file is broken because of invalid RegExps. The escaping for
ns.regShortNames
,ns.regAscii
andns.regUnicode
is stripped and therefore they become invalid.