Skip to content

Commit 15c549c

Browse files
committed
Merge pull request #92 from jayroh/cgi-escape-emoji-name
CGI.escape emoji name
2 parents b659a9e + 90d51ef commit 15c549c

File tree

2 files changed

+16
-2
lines changed

2 files changed

+16
-2
lines changed

lib/html/pipeline/emoji_filter.rb

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
require "cgi"
2+
13
begin
24
require "gemoji"
35
rescue LoadError => _
@@ -42,7 +44,7 @@ def emoji_image_filter(text)
4244

4345
text.gsub EmojiPattern do |match|
4446
name = $1
45-
"<img class='emoji' title=':#{name}:' alt=':#{name}:' src='#{File.join(asset_root, "emoji", "#{name}.png")}' height='20' width='20' align='absmiddle' />"
47+
"<img class='emoji' title=':#{name}:' alt=':#{name}:' src='#{emoji_url(name)}' height='20' width='20' align='absmiddle' />"
4648
end
4749
end
4850

@@ -53,6 +55,12 @@ def emoji_image_filter(text)
5355
def asset_root
5456
context[:asset_root]
5557
end
58+
59+
private
60+
61+
def emoji_url(name)
62+
File.join(asset_root, "emoji", "#{::CGI.escape(name)}.png")
63+
end
5664
end
5765
end
5866
end

test/html/pipeline/emoji_filter_test.rb

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,16 @@ def test_emojify
99
assert_match "https://foo.com/emoji/shipit.png", doc.search('img').attr('src').value
1010
end
1111

12+
def test_uri_encoding
13+
filter = EmojiFilter.new("<p>:+1:</p>", {:asset_root => 'https://foo.com'})
14+
doc = filter.call
15+
assert_match "https://foo.com/emoji/%2B1.png", doc.search('img').attr('src').value
16+
end
17+
1218
def test_required_context_validation
1319
exception = assert_raise(ArgumentError) {
1420
EmojiFilter.call("", {})
1521
}
1622
assert_match /:asset_root/, exception.message
1723
end
18-
end
24+
end

0 commit comments

Comments
 (0)