Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Validate characters passed through the Emoji constructor #793

Closed
wants to merge 2 commits into from

Conversation

foxbot
Copy link
Member

@foxbot foxbot commented Aug 15, 2017

Abstract

This experiment adds support for Emojis to be validated against Unicode's restrictions, which should prevent misuse of the Emoji class, and prevent accidental 400 errors from Discord when attempting to add a reaction with a bad payload.

Additions

Breaking: Should any string be passed that contains a character that is NOT valid in an Emoji, an exception will be thrown.0

This experiment uses a T4 template to fetch the latest Emoji data from Unicode, and build a constant collection of valid emoji codepoints that will be cross-checked at runtime. This is exposed as an internal collection on Discord.Emoji.1

Changes

When passing a string into the Discord.Emoji constructor on platforms targeting .NET Standard 1.3+ or .NET Framework 4.5, every character in the argument will be converted to a UTF32 codepoint, and verified against the codepoints, as described above.2

Tests

This pull request is bundled with tests that should verify most aspects of the new parser work as they should, including single-part and multi-part emojis. Discord-style Emotes are also now tested against.3

This pull request has been tested in production, and is proven to parse both single-part and multi-part Emojis.4

Possible Caveats:

Some Emojis are only valid when used in conjunction with a marker character, e.g. 1️⃣, which is composed of a DIGIT ONE and a COMBINING ENCLOSING KEYCAP. Under this PR, a single DIGIT ONE will be parsed as valid. I'm unsure whether or not Discord will reject a reaction with this Emoji, since Unicode lists the digit character range (0x30..0x39) as both an Emoji and an Emoji_Component.5

@foxbot
Copy link
Member Author

foxbot commented Nov 7, 2018

Closing since .NET Core does not support T4 generators; this will be redone with a different implementation though.

@foxbot foxbot closed this Nov 7, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant