FIX: Fix the emoji toned regexes (#20763)

This commit is contained in:
Daniel Waterworth 2023-03-21 11:48:55 -05:00 committed by GitHub
parent 0562f952ed
commit a0a6f6d71b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 9 additions and 2 deletions

View File

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

View File

@ -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 "doesnt find non-existing emoji" do
expect(Emoji.exists?(":foo-bar:")).to be(false)
expect(Emoji.exists?(":blonde_woman:t7:")).to be(false)