mirror of
https://github.com/discourse/discourse.git
synced 2024-11-22 15:25:35 +08:00
DEV: Add Custom emoji sanitization (#22697)
* DEV: Add Custom emoji sanitization * added tests for implemented changes
This commit is contained in:
parent
9650bf9d08
commit
9e83d64723
|
@ -684,6 +684,7 @@ class Plugin::Instance
|
|||
end
|
||||
|
||||
def register_emoji(name, url, group = Emoji::DEFAULT_GROUP)
|
||||
name = name.gsub(/[^a-z0-9]+/i, "_").gsub(/_{2,}/, "_").downcase
|
||||
Plugin::CustomEmoji.register(name, url, group)
|
||||
Emoji.clear_cache
|
||||
end
|
||||
|
|
|
@ -589,6 +589,14 @@ RSpec.describe Plugin::Instance do
|
|||
expect(custom_emoji.url).to eq("/baz/bar.png")
|
||||
expect(custom_emoji.group).to eq("baz")
|
||||
end
|
||||
|
||||
it "sanitizes emojis' names" do
|
||||
Plugin::Instance.new.register_emoji("?", "/baz/bar.png", "baz")
|
||||
Plugin::Instance.new.register_emoji("?test?!!", "/foo/bar.png", "baz")
|
||||
|
||||
expect(Emoji.custom.first.name).to eq("_")
|
||||
expect(Emoji.custom.second.name).to eq("_test_")
|
||||
end
|
||||
end
|
||||
|
||||
describe "#replace_flags" do
|
||||
|
|
Loading…
Reference in New Issue
Block a user