mirror of
https://github.com/discourse/discourse.git
synced 2024-11-25 18:30:26 -06:00
FIX: unescape emoji in pretty title
This makes emoji in title consistent, it is later escaped back when needed
This commit is contained in:
parent
b839eb41ff
commit
44d7fe89ed
@ -146,6 +146,16 @@ class Emoji
|
||||
@unicode_replacements
|
||||
end
|
||||
|
||||
def self.unicode_unescape(string)
|
||||
string.each_char.map do |c|
|
||||
if str = unicode_replacements[c]
|
||||
":#{str}:"
|
||||
else
|
||||
c
|
||||
end
|
||||
end.join
|
||||
end
|
||||
|
||||
def self.lookup_unicode(name)
|
||||
@reverse_map ||= begin
|
||||
map = {}
|
||||
|
@ -295,7 +295,7 @@ class Topic < ActiveRecord::Base
|
||||
def self.fancy_title(title)
|
||||
escaped = ERB::Util.html_escape(title)
|
||||
return unless escaped
|
||||
HtmlPrettify.render(escaped)
|
||||
Emoji.unicode_unescape(HtmlPrettify.render(escaped))
|
||||
end
|
||||
|
||||
def fancy_title
|
||||
|
@ -257,11 +257,16 @@ describe Topic do
|
||||
let(:topic_bold) { build_topic_with_title("Topic with <b>bold</b> text in its title" ) }
|
||||
let(:topic_image) { build_topic_with_title("Topic with <img src='something'> image in its title" ) }
|
||||
let(:topic_script) { build_topic_with_title("Topic with <script>alert('title')</script> script in its title" ) }
|
||||
let(:topic_emoji) { build_topic_with_title("I 💖 candy alot") }
|
||||
|
||||
it "escapes script contents" do
|
||||
expect(topic_script.fancy_title).to eq("Topic with <script>alert(‘title’)</script> script in its title")
|
||||
end
|
||||
|
||||
it "expands emojis" do
|
||||
expect(topic_emoji.fancy_title).to eq("I :sparkling_heart: candy alot")
|
||||
end
|
||||
|
||||
it "escapes bold contents" do
|
||||
expect(topic_bold.fancy_title).to eq("Topic with <b>bold</b> text in its title")
|
||||
end
|
||||
|
Loading…
Reference in New Issue
Block a user