class Gitlab::Dangerfiles::EmojiChecker
@api private
Constants
- ALIASES
- DIGESTS
- LIKELY_EMOJI
A regex that indicates a piece of text might include an Emoji. The regex alone is not enough, as we'd match `:foo:bar:baz`. Instead, we use this regex to save us from having to check for all possible emoji names when we know one definitely is not included.
- UNICODE_EMOJI_REGEX
Public Class Methods
new()
click to toggle source
# File lib/gitlab/dangerfiles/emoji_checker.rb, line 28 def initialize names = JSON.parse(File.read(DIGESTS)).keys + JSON.parse(File.read(ALIASES)).keys @emoji = names.map { |name| ":#{name}:" } end
Public Instance Methods
includes_text_emoji?(text)
click to toggle source
# File lib/gitlab/dangerfiles/emoji_checker.rb, line 35 def includes_text_emoji?(text) return false unless text.match?(LIKELY_EMOJI) @emoji.any? { |emoji| text.include?(emoji) } end
includes_unicode_emoji?(text)
click to toggle source
# File lib/gitlab/dangerfiles/emoji_checker.rb, line 41 def includes_unicode_emoji?(text) text.match?(UNICODE_EMOJI_REGEX) end