fix: Obay variant selectors for emoji regex
This commit is contained in:
parent
d42979da12
commit
0ff971faa9
|
@ -770,7 +770,7 @@ class Event extends MatrixEvent {
|
|||
|
||||
// regexes to fetch the number of emotes, including emoji, and if the message consists of only those
|
||||
// to match an emoji we can use the following regex:
|
||||
// \x{00a9}|\x{00ae}|[\x{2000}-\x{3300}]|\x{d83c}[\x{d000}-\x{dfff}]|\x{d83d}[\x{d000}-\x{dfff}]|\x{d83e}[\x{d000}-\x{dfff}]
|
||||
// (?:\x{00a9}|\x{00ae}|[\x{2000}-\x{3300}]|\x{d83c}[\x{d000}-\x{dfff}]|\x{d83d}[\x{d000}-\x{dfff}]|\x{d83e}[\x{d000}-\x{dfff}])[\x{fe00}-\x{fe0f}]?
|
||||
// we need to replace \x{0000} with \u0000, the comment is left in the other format to be able to paste into regex101.com
|
||||
// to see if there is a custom emote, we use the following regex: <img[^>]+data-mx-(?:emote|emoticon)(?==|>|\s)[^>]*>
|
||||
// now we combind the two to have four regexes:
|
||||
|
@ -779,19 +779,19 @@ class Event extends MatrixEvent {
|
|||
// 3. count number of emoji
|
||||
// 4- count number of emoji or emotes
|
||||
static final RegExp _onlyEmojiRegex = RegExp(
|
||||
r'^(\u00a9|\u00ae|[\u2000-\u3300]|\ud83c[\ud000-\udfff]|\ud83d[\ud000-\udfff]|\ud83e[\ud000-\udfff]|\s)*$',
|
||||
r'^((?:\u00a9|\u00ae|[\u2000-\u3300]|\ud83c[\ud000-\udfff]|\ud83d[\ud000-\udfff]|\ud83e[\ud000-\udfff])[\ufe00-\ufe0f]?|\s)*$',
|
||||
caseSensitive: false,
|
||||
multiLine: false);
|
||||
static final RegExp _onlyEmojiEmoteRegex = RegExp(
|
||||
r'^(\u00a9|\u00ae|[\u2000-\u3300]|\ud83c[\ud000-\udfff]|\ud83d[\ud000-\udfff]|\ud83e[\ud000-\udfff]|<img[^>]+data-mx-(?:emote|emoticon)(?==|>|\s)[^>]*>|\s)*$',
|
||||
r'^((?:\u00a9|\u00ae|[\u2000-\u3300]|\ud83c[\ud000-\udfff]|\ud83d[\ud000-\udfff]|\ud83e[\ud000-\udfff])[\ufe00-\ufe0f]?|<img[^>]+data-mx-(?:emote|emoticon)(?==|>|\s)[^>]*>|\s)*$',
|
||||
caseSensitive: false,
|
||||
multiLine: false);
|
||||
static final RegExp _countEmojiRegex = RegExp(
|
||||
r'(\u00a9|\u00ae|[\u2000-\u3300]|\ud83c[\ud000-\udfff]|\ud83d[\ud000-\udfff]|\ud83e[\ud000-\udfff])',
|
||||
r'((?:\u00a9|\u00ae|[\u2000-\u3300]|\ud83c[\ud000-\udfff]|\ud83d[\ud000-\udfff]|\ud83e[\ud000-\udfff])[\ufe00-\ufe0f]?)',
|
||||
caseSensitive: false,
|
||||
multiLine: false);
|
||||
static final RegExp _countEmojiEmoteRegex = RegExp(
|
||||
r'(\u00a9|\u00ae|[\u2000-\u3300]|\ud83c[\ud000-\udfff]|\ud83d[\ud000-\udfff]|\ud83e[\ud000-\udfff]|<img[^>]+data-mx-(?:emote|emoticon)(?==|>|\s)[^>]*>)',
|
||||
r'((?:\u00a9|\u00ae|[\u2000-\u3300]|\ud83c[\ud000-\udfff]|\ud83d[\ud000-\udfff]|\ud83e[\ud000-\udfff])[\ufe00-\ufe0f]?|<img[^>]+data-mx-(?:emote|emoticon)(?==|>|\s)[^>]*>)',
|
||||
caseSensitive: false,
|
||||
multiLine: false);
|
||||
|
||||
|
|
|
@ -1267,6 +1267,18 @@ void main() {
|
|||
}, null);
|
||||
expect(event.onlyEmotes, true);
|
||||
expect(event.numberEmotes, 2);
|
||||
// with variant selector
|
||||
event = Event.fromJson({
|
||||
'type': EventTypes.Message,
|
||||
'content': {
|
||||
'msgtype': 'm.text',
|
||||
'body': '❤️',
|
||||
},
|
||||
'event_id': '\$edit2',
|
||||
'sender': '@alice:example.org',
|
||||
}, null);
|
||||
expect(event.onlyEmotes, true);
|
||||
expect(event.numberEmotes, 1);
|
||||
});
|
||||
});
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue