From ab6086bce9588b9141d7977d6360227a2bfbfc86 Mon Sep 17 00:00:00 2001 From: Joffrey JAFFEUX Date: Wed, 14 Jun 2017 15:35:37 +0200 Subject: [PATCH] Transforms native skin toned emojis to valid names --- app/models/emoji.rb | 13 +++++++++++-- spec/components/pretty_text_spec.rb | 4 ++++ 2 files changed, 15 insertions(+), 2 deletions(-) diff --git a/app/models/emoji.rb b/app/models/emoji.rb index 0f0b5104404..fa71bd6a1fc 100644 --- a/app/models/emoji.rb +++ b/app/models/emoji.rb @@ -116,12 +116,21 @@ class Emoji def self.unicode_replacements return @unicode_replacements if @unicode_replacements - @unicode_replacements = {} + db['emojis'].each do |e| next if e['name'] == 'tm' + code = replacement_code(e['code']) - @unicode_replacements[code] = e['name'] if code + next unless code + + @unicode_replacements[code] = e['name'] + if Emoji.tonable_emojis.include?(e['name']) + FITZPATRICK_SCALE.each_with_index do |scale, index| + toned_code = (code.codepoints.insert(1, scale.to_i(16))).pack("U*") + @unicode_replacements[toned_code] = "#{e['name']}:t#{index+2}" + end + end end @unicode_replacements["\u{2639}"] = 'frowning' diff --git a/spec/components/pretty_text_spec.rb b/spec/components/pretty_text_spec.rb index 4fa7b9b6060..cdfa0244321 100644 --- a/spec/components/pretty_text_spec.rb +++ b/spec/components/pretty_text_spec.rb @@ -453,6 +453,10 @@ HTML SiteSetting.enable_emoji = false expect(PrettyText.cook("💣")).not_to match(/\:bomb\:/) end + + it "replaces skin toned emoji" do + expect(PrettyText.cook("hello 👱🏿‍♀️")).to eq("

hello \":blonde_woman:t6:\"

") + end end describe "tag and category links" do