DEV: Add Custom emoji sanitization (#22697)

* DEV: Add Custom emoji sanitization

* added tests for implemented changes
This commit is contained in:
Juan David Martínez Cubillos 2023-07-19 14:09:26 -05:00 committed by GitHub
parent 9650bf9d08
commit 9e83d64723
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 9 additions and 0 deletions

View File

@ -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

View File

@ -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