From 74780c168841c67985cc8a0b26127df200350a4f Mon Sep 17 00:00:00 2001 From: Robin Ward Date: Wed, 30 Dec 2015 14:46:52 -0500 Subject: [PATCH] Add more server side unicode replacements for emoji --- app/models/emoji.rb | 11 ++++++++++- spec/components/pretty_text_spec.rb | 4 ++++ 2 files changed, 14 insertions(+), 1 deletion(-) diff --git a/app/models/emoji.rb b/app/models/emoji.rb index 4d695f09ff7..e65b91e0d7a 100644 --- a/app/models/emoji.rb +++ b/app/models/emoji.rb @@ -119,7 +119,16 @@ class Emoji end def self.unicode_replacements - @unicode_replacements ||= Hash[db.map {|e| [e['emoji'], e['aliases'][0]] }] + return @unicode_replacements if @unicode_replacements + + @unicode_replacements = Hash[db.map {|e| [e['emoji'], e['aliases'][0]] }] + @unicode_replacements["\u{2639}"] = 'frowning' + @unicode_replacements["\u{263A}"] = 'slightly_smiling' + @unicode_replacements["\u{263B}"] = 'slightly_smiling' + @unicode_replacements["\u{2661}"] = 'heart' + @unicode_replacements["\u{2665}"] = 'heart' + + @unicode_replacements end def self.unicode_regexp diff --git a/spec/components/pretty_text_spec.rb b/spec/components/pretty_text_spec.rb index 4fd92a84570..f9cd29081c3 100644 --- a/spec/components/pretty_text_spec.rb +++ b/spec/components/pretty_text_spec.rb @@ -385,6 +385,10 @@ HTML expect(PrettyText.cook("💣")).to match(/\:bomb\:/) end + it "replaces some glyphs that are not in the emoji range" do + expect(PrettyText.cook("☺")).to match(/\:slightly_smiling\:/) + end + it "doesn't replace unicode emoji if emoji is disabled" do SiteSetting.enable_emoji = false expect(PrettyText.cook("💣")).not_to match(/\:bomb\:/)