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
0
Merge Requests
0
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
Léo-Paul Géneau
gitlab-ce
Commits
a8a52a58
Commit
a8a52a58
authored
Mar 16, 2017
by
Eric Eastwood
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Protect against unknown emojis in frequently used list
See
https://gitlab.slack.com/archives/frontend/p1489690607738864
parent
ce5d1b6f
Changes
5
Show whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
89 additions
and
9 deletions
+89
-9
app/assets/javascripts/awards_handler.js
app/assets/javascripts/awards_handler.js
+13
-5
app/assets/javascripts/behaviors/gl_emoji.js
app/assets/javascripts/behaviors/gl_emoji.js
+15
-4
app/assets/javascripts/behaviors/gl_emoji/is_emoji_name_valid.js
...ets/javascripts/behaviors/gl_emoji/is_emoji_name_valid.js
+11
-0
spec/javascripts/awards_handler_spec.js
spec/javascripts/awards_handler_spec.js
+14
-0
spec/javascripts/gl_emoji_spec.js
spec/javascripts/gl_emoji_spec.js
+36
-0
No files found.
app/assets/javascripts/awards_handler.js
View file @
a8a52a58
...
...
@@ -3,6 +3,7 @@
import
emojiMap
from
'
emojis/digests.json
'
;
import
emojiAliases
from
'
emojis/aliases.json
'
;
import
{
glEmojiTag
}
from
'
./behaviors/gl_emoji
'
;
import
isEmojiNameValid
from
'
./behaviors/gl_emoji/is_emoji_name_valid
'
;
const
animationEndEventString
=
'
animationend webkitAnimationEnd MSAnimationEnd oAnimationEnd
'
;
const
requestAnimationFrame
=
window
.
requestAnimationFrame
||
...
...
@@ -454,14 +455,21 @@ AwardsHandler.prototype.normalizeEmojiName = function normalizeEmojiName(emoji)
AwardsHandler
.
prototype
.
addEmojiToFrequentlyUsedList
=
function
addEmojiToFrequentlyUsedList
(
emoji
)
{
const
frequentlyUsedEmojis
=
this
.
getFrequentlyUsedEmojis
();
frequentlyUsedEmojis
.
push
(
emoji
);
Cookies
.
set
(
'
frequently_used_emojis
'
,
frequentlyUsedEmojis
.
join
(
'
,
'
),
{
expires
:
365
});
if
(
isEmojiNameValid
(
emoji
))
{
this
.
frequentlyUsedEmojis
=
_
.
uniq
(
this
.
getFrequentlyUsedEmojis
().
concat
(
emoji
));
Cookies
.
set
(
'
frequently_used_emojis
'
,
this
.
frequentlyUsedEmojis
.
join
(
'
,
'
),
{
expires
:
365
});
}
};
AwardsHandler
.
prototype
.
getFrequentlyUsedEmojis
=
function
getFrequentlyUsedEmojis
()
{
const
frequentlyUsedEmojis
=
(
Cookies
.
get
(
'
frequently_used_emojis
'
)
||
''
).
split
(
'
,
'
);
return
_
.
compact
(
_
.
uniq
(
frequentlyUsedEmojis
));
return
this
.
frequentlyUsedEmojis
||
(()
=>
{
const
frequentlyUsedEmojis
=
_
.
uniq
((
Cookies
.
get
(
'
frequently_used_emojis
'
)
||
''
).
split
(
'
,
'
));
this
.
frequentlyUsedEmojis
=
frequentlyUsedEmojis
.
filter
(
inputName
=>
isEmojiNameValid
(
inputName
),
);
return
this
.
frequentlyUsedEmojis
;
})();
};
AwardsHandler
.
prototype
.
setupSearch
=
function
setupSearch
()
{
...
...
app/assets/javascripts/behaviors/gl_emoji.js
View file @
a8a52a58
...
...
@@ -13,9 +13,14 @@ function emojiImageTag(name, src) {
}
function
assembleFallbackImageSrc
(
inputName
)
{
cons
t
name
=
Object
.
prototype
.
hasOwnProperty
.
call
(
emojiAliases
,
inputName
)
?
le
t
name
=
Object
.
prototype
.
hasOwnProperty
.
call
(
emojiAliases
,
inputName
)
?
emojiAliases
[
inputName
]
:
inputName
;
const
emojiInfo
=
emojiMap
[
name
];
let
emojiInfo
=
emojiMap
[
name
];
// Fallback to question mark for unknown emojis
if
(
!
emojiInfo
)
{
name
=
'
grey_question
'
;
emojiInfo
=
emojiMap
[
name
];
}
const
fallbackImageSrc
=
`
${
gon
.
asset_host
||
''
}${
gon
.
relative_url_root
||
''
}
/assets/emoji/
${
name
}
-
${
emojiInfo
.
digest
}
.png`
;
return
fallbackImageSrc
;
...
...
@@ -26,9 +31,15 @@ const glEmojiTagDefaults = {
};
function
glEmojiTag
(
inputName
,
options
)
{
const
opts
=
Object
.
assign
({},
glEmojiTagDefaults
,
options
);
cons
t
name
=
Object
.
prototype
.
hasOwnProperty
.
call
(
emojiAliases
,
inputName
)
?
le
t
name
=
Object
.
prototype
.
hasOwnProperty
.
call
(
emojiAliases
,
inputName
)
?
emojiAliases
[
inputName
]
:
inputName
;
const
emojiInfo
=
emojiMap
[
name
];
let
emojiInfo
=
emojiMap
[
name
];
// Fallback to question mark for unknown emojis
if
(
!
emojiInfo
)
{
name
=
'
grey_question
'
;
emojiInfo
=
emojiMap
[
name
];
}
const
fallbackImageSrc
=
assembleFallbackImageSrc
(
name
);
const
fallbackSpriteClass
=
`emoji-
${
name
}
`
;
...
...
app/assets/javascripts/behaviors/gl_emoji/is_emoji_name_valid.js
0 → 100644
View file @
a8a52a58
import
emojiMap
from
'
emojis/digests.json
'
;
import
emojiAliases
from
'
emojis/aliases.json
'
;
function
isEmojiNameValid
(
inputName
)
{
const
name
=
Object
.
prototype
.
hasOwnProperty
.
call
(
emojiAliases
,
inputName
)
?
emojiAliases
[
inputName
]
:
inputName
;
return
name
&&
emojiMap
[
name
];
}
export
default
isEmojiNameValid
;
spec/javascripts/awards_handler_spec.js
View file @
a8a52a58
...
...
@@ -287,6 +287,20 @@ import AwardsHandler from '~/awards_handler';
done
.
fail
(
`Failed to open and build emoji menu:
${
err
.
message
}
`
);
});
});
it
(
'
should disregard invalid frequently used emoji that are being attempted to be added
'
,
function
()
{
awardsHandler
.
addEmojiToFrequentlyUsedList
(
'
8ball
'
);
awardsHandler
.
addEmojiToFrequentlyUsedList
(
'
invalid_emoji
'
);
awardsHandler
.
addEmojiToFrequentlyUsedList
(
'
grinning
'
);
expect
(
awardsHandler
.
getFrequentlyUsedEmojis
()).
toEqual
([
'
8ball
'
,
'
grinning
'
]);
});
it
(
'
should disregard invalid frequently used emoji already set in cookie
'
,
function
()
{
Cookies
.
set
(
'
frequently_used_emojis
'
,
'
8ball,invalid_emoji,grinning
'
);
expect
(
awardsHandler
.
getFrequentlyUsedEmojis
()).
toEqual
([
'
8ball
'
,
'
grinning
'
]);
});
});
});
}).
call
(
window
);
spec/javascripts/gl_emoji_spec.js
View file @
a8a52a58
...
...
@@ -43,6 +43,11 @@ const emojiFixtureMap = {
moji
:
'
5️⃣
'
,
unicodeVersion
:
'
3.0
'
,
},
grey_question
:
{
name
:
'
grey_question
'
,
moji
:
'
❔
'
,
unicodeVersion
:
'
6.0
'
,
},
};
function
markupToDomElement
(
markup
)
{
...
...
@@ -153,6 +158,37 @@ describe('gl_emoji', () => {
},
);
});
it
(
'
question mark when invalid emoji name given
'
,
()
=>
{
const
name
=
'
invalid_emoji
'
;
const
emojiKey
=
'
grey_question
'
;
const
markup
=
glEmojiTag
(
name
);
const
glEmojiElement
=
markupToDomElement
(
markup
);
testGlEmojiElement
(
glEmojiElement
,
emojiFixtureMap
[
emojiKey
].
name
,
emojiFixtureMap
[
emojiKey
].
unicodeVersion
,
emojiFixtureMap
[
emojiKey
].
moji
,
);
});
it
(
'
question mark with image fallback when invalid emoji name given
'
,
()
=>
{
const
name
=
'
invalid_emoji
'
;
const
emojiKey
=
'
grey_question
'
;
const
markup
=
glEmojiTag
(
name
,
{
forceFallback
:
true
,
});
const
glEmojiElement
=
markupToDomElement
(
markup
);
testGlEmojiElement
(
glEmojiElement
,
emojiFixtureMap
[
emojiKey
].
name
,
emojiFixtureMap
[
emojiKey
].
unicodeVersion
,
emojiFixtureMap
[
emojiKey
].
moji
,
{
forceFallback
:
true
,
},
);
});
});
describe
(
'
isFlagEmoji
'
,
()
=>
{
...
...
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