FIX: Sanitization issue when replacing default emoji with custom emoji that contains or ~/Discourse/discourse symbols (#30053)

This commit is contained in:
Juan David Martínez Cubillos 2024-12-03 19:27:12 -05:00 committed by GitHub
parent 45c9d1d81f
commit 7b70905326
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 5 additions and 1 deletions

View File

@ -327,6 +327,6 @@ class Emoji
end end
def self.sanitize_emoji_name(name) def self.sanitize_emoji_name(name)
name.gsub(/[^a-z0-9]+/i, "_").gsub(/_{2,}/, "_").downcase name.gsub(/[^a-z0-9\+\-]+/i, "_").gsub(/_{2,}/, "_").downcase
end end
end end

View File

@ -706,9 +706,13 @@ TEXT
it "sanitizes emojis' names" do it "sanitizes emojis' names" do
Plugin::Instance.new.register_emoji("?", "/baz/bar.png", "baz") Plugin::Instance.new.register_emoji("?", "/baz/bar.png", "baz")
Plugin::Instance.new.register_emoji("?test?!!", "/foo/bar.png", "baz") Plugin::Instance.new.register_emoji("?test?!!", "/foo/bar.png", "baz")
Plugin::Instance.new.register_emoji("+1", "/foo/bar.png", "baz")
Plugin::Instance.new.register_emoji("test!-1", "/foo/bar.png", "baz")
expect(Emoji.custom.first.name).to eq("_") expect(Emoji.custom.first.name).to eq("_")
expect(Emoji.custom.second.name).to eq("_test_") expect(Emoji.custom.second.name).to eq("_test_")
expect(Emoji.custom.third.name).to eq("+1")
expect(Emoji.custom.fourth.name).to eq("test_-1")
end end
end end