Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
G
gitlab-ce
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
1
Merge Requests
1
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
nexedi
gitlab-ce
Commits
cf124760
Commit
cf124760
authored
Oct 16, 2020
by
Brett Walker
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Filter out trademark and copyright from emojis
and display them as unicode characters rather than images.
parent
9f5f35ed
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
26 additions
and
1 deletion
+26
-1
changelogs/unreleased/17652-trademark-and-copyright-symbols-converted-to-smiley.yml
...2-trademark-and-copyright-symbols-converted-to-smiley.yml
+6
-0
lib/banzai/filter/emoji_filter.rb
lib/banzai/filter/emoji_filter.rb
+6
-1
spec/lib/banzai/filter/emoji_filter_spec.rb
spec/lib/banzai/filter/emoji_filter_spec.rb
+14
-0
No files found.
changelogs/unreleased/17652-trademark-and-copyright-symbols-converted-to-smiley.yml
0 → 100644
View file @
cf124760
---
title
:
Do not convert unicode versions of trademark, copyright,
and registered trademark to emoji
merge_request
:
45457
author
:
type
:
fixed
lib/banzai/filter/emoji_filter.rb
View file @
cf124760
...
...
@@ -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
...
...
spec/lib/banzai/filter/emoji_filter_spec.rb
View file @
cf124760
...
...
@@ -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
'👍'
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment