BigW Consortium Gitlab
Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
G
gitlab-ce
Project
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
Registry
Registry
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Commits
Issue Boards
Open sidebar
Forest Godfrey
gitlab-ce
Commits
f7769bbd
Commit
f7769bbd
authored
Mar 17, 2017
by
Alfredo Sumaran
Committed by
Lin Jen-Shin
Mar 17, 2017
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Merge branch 'fix-unknown-emojis-in-frequently-used-awards' into 'master'
Protect against unknown emojis in frequently used list See merge request !10020
parent
b6de7944
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
89 additions
and
9 deletions
+89
-9
awards_handler.js
app/assets/javascripts/awards_handler.js
+13
-5
gl_emoji.js
app/assets/javascripts/behaviors/gl_emoji.js
+15
-4
is_emoji_name_valid.js
...ets/javascripts/behaviors/gl_emoji/is_emoji_name_valid.js
+11
-0
awards_handler_spec.js
spec/javascripts/awards_handler_spec.js
+14
-0
gl_emoji_spec.js
spec/javascripts/gl_emoji_spec.js
+36
-0
No files found.
app/assets/javascripts/awards_handler.js
View file @
f7769bbd
...
...
@@ -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 @
f7769bbd
...
...
@@ -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 @
f7769bbd
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 @
f7769bbd
...
...
@@ -293,6 +293,20 @@ promisePolyfill.polyfill();
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 @
f7769bbd
...
...
@@ -46,6 +46,11 @@ const emojiFixtureMap = {
moji
:
'5️⃣'
,
unicodeVersion
:
'3.0'
,
},
grey_question
:
{
name
:
'grey_question'
,
moji
:
'❔'
,
unicodeVersion
:
'6.0'
,
},
};
function
markupToDomElement
(
markup
)
{
...
...
@@ -156,6 +161,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