From 7b70905326d62c02077e8e01e8e4c72efe0d667f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Juan=20David=20Mart=C3=ADnez=20Cubillos?= Date: Tue, 3 Dec 2024 19:27:12 -0500 Subject: [PATCH] FIX: Sanitization issue when replacing default emoji with custom emoji that contains or ~/Discourse/discourse symbols (#30053) --- app/models/emoji.rb | 2 +- spec/lib/plugin/instance_spec.rb | 4 ++++ 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/app/models/emoji.rb b/app/models/emoji.rb index 33bc4657e49..89a1b5a2d4e 100644 --- a/app/models/emoji.rb +++ b/app/models/emoji.rb @@ -327,6 +327,6 @@ class Emoji end 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 diff --git a/spec/lib/plugin/instance_spec.rb b/spec/lib/plugin/instance_spec.rb index 37e93b1cb4a..172c48d4893 100644 --- a/spec/lib/plugin/instance_spec.rb +++ b/spec/lib/plugin/instance_spec.rb @@ -706,9 +706,13 @@ TEXT it "sanitizes emojis' names" do Plugin::Instance.new.register_emoji("?", "/baz/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.second.name).to eq("_test_") + expect(Emoji.custom.third.name).to eq("+1") + expect(Emoji.custom.fourth.name).to eq("test_-1") end end