Skip to content

A platform for community discussion. Free, open, simple.

FIX: Fix the emoji toned regexes (#20763)

Daniel Waterwortha0a6f6d71b6b
diff --git a/app/models/emoji.rb b/app/models/emoji.rb
index cddd9042c0e..bf4a2d6164d 100644
--- a/app/models/emoji.rb
+++ b/app/models/emoji.rb
@@ -59,8 +59,8 @@ class Emoji
def self.[](name)
name = name.delete_prefix(":").delete_suffix(":")
- is_toned = name.match?(/.+:t[1-6]/)
- normalized_name = name.gsub(/(.+):t[1-6]/, '\1')
+ is_toned = name.match?(/\A.+:t[1-6]\z/)
+ normalized_name = name.gsub(/\A(.+):t[1-6]\z/, '\1')
found_emoji = nil
diff --git a/spec/models/emoji_spec.rb b/spec/models/emoji_spec.rb
index 4c081717bf5..208a6922f21 100644
--- a/spec/models/emoji_spec.rb
+++ b/spec/models/emoji_spec.rb
@@ -76,6 +76,13 @@ RSpec.describe Emoji do
expect(Emoji.exists?("test")).to be(true)
end
+ it "finds a custom emoji with a name with :t1 in the middle" do
+ CustomEmoji.create!(name: "test:t1:foo", upload_id: 9999)
+ Emoji.clear_cache
+ expect(Emoji.exists?(":test:t1:foo:")).to be(true)
+ expect(Emoji.exists?("test:t1:foo")).to be(true)
+ end
+
it "doesn’t find non-existing emoji" do
expect(Emoji.exists?(":foo-bar:")).to be(false)
expect(Emoji.exists?(":blonde_woman:t7:")).to be(false)