Commit a2cd7c71 authored by Dmytro Zaporozhets (DZ)'s avatar Dmytro Zaporozhets (DZ)

Merge branch '17652-trademark-and-copyright-symbols-converted-to-smiley' into 'master'

Do not convert unicode versions of trademark, copyright, and registered trademark to emoji

See merge request gitlab-org/gitlab!45457
parents c7a0a863 cf124760
---
title: Do not convert unicode versions of trademark, copyright,
and registered trademark to emoji
merge_request: 45457
author:
type: fixed
......@@ -8,6 +8,7 @@ module Banzai
# Based on HTML::Pipeline::EmojiFilter
class EmojiFilter < HTML::Pipeline::Filter
IGNORED_ANCESTOR_TAGS = %w(pre code tt).to_set
IGNORE_UNICODE_EMOJIS = %w(™ © ®).freeze
def call
doc.search(".//text()").each do |node|
......@@ -60,7 +61,11 @@ module Banzai
# Build a regexp that matches all valid unicode emojis names.
def self.emoji_unicode_pattern
@emoji_unicode_pattern ||= /(#{Gitlab::Emoji.emojis_unicodes.map { |moji| Regexp.escape(moji) }.join('|')})/
@emoji_unicode_pattern ||=
begin
filtered_emojis = Gitlab::Emoji.emojis_unicodes - IGNORE_UNICODE_EMOJIS
/(#{filtered_emojis.map { |moji| Regexp.escape(moji) }.join('|')})/
end
end
private
......
......@@ -21,6 +21,20 @@ RSpec.describe Banzai::Filter::EmojiFilter do
expect(doc.to_html).to match Regexp.escape(exp)
end
it 'ignores unicode versions of trademark, copyright, and registered trademark' do
exp = act = '<p>™ © ®</p>'
doc = filter(act)
expect(doc.to_html).to match Regexp.escape(exp)
end
it 'replaces name versions of trademark, copyright, and registered trademark' do
doc = filter('<p>:tm: :copyright: :registered:</p>')
expect(doc.css('gl-emoji')[0].text).to eq '™'
expect(doc.css('gl-emoji')[1].text).to eq '©'
expect(doc.css('gl-emoji')[2].text).to eq '®'
end
it 'correctly encodes the URL' do
doc = filter('<p>:+1:</p>')
expect(doc.css('gl-emoji').first.text).to eq '👍'
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment