From a0a6f6d71b6bf2b80a0f51f0674b992df9351574 Mon Sep 17 00:00:00 2001 From: Daniel Waterworth Date: Tue, 21 Mar 2023 11:48:55 -0500 Subject: [PATCH] FIX: Fix the emoji toned regexes (#20763) --- app/models/emoji.rb | 4 ++-- spec/models/emoji_spec.rb | 7 +++++++ 2 files changed, 9 insertions(+), 2 deletions(-) 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)