fix: fix custom emoji in polls (#1619)

fixes #1617
This commit is contained in:
Nolan Lawson 2019-10-31 23:01:35 -07:00 committed by GitHub
parent ee492c1765
commit 4ecb04588c
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 38 additions and 7 deletions

View file

@ -4,7 +4,7 @@
{#each options as option} {#each options as option}
<li class="poll-choice option"> <li class="poll-choice option">
<div class="option-text"> <div class="option-text">
<strong>{option.share}%</strong> {option.title} <strong>{option.share}%</strong> <span>{@html option.title}</span>
</div> </div>
<svg aria-hidden="true"> <svg aria-hidden="true">
<line x1="0" y1="0" x2="{option.share}%" y2="0" /> <line x1="0" y1="0" x2="{option.share}%" y2="0" />
@ -23,7 +23,7 @@
value="{i}" value="{i}"
on:change="onChange()" on:change="onChange()"
> >
<span>{option.title}</span> <span>{@html option.title}</span>
</label> </label>
</li> </li>
{/each} {/each}
@ -245,6 +245,8 @@
import { registerClickDelegate } from '../../_utils/delegate' import { registerClickDelegate } from '../../_utils/delegate'
import { classname } from '../../_utils/classname' import { classname } from '../../_utils/classname'
import { getPoll, voteOnPoll } from '../../_actions/polls' import { getPoll, voteOnPoll } from '../../_actions/polls'
import escapeHtml from 'escape-html'
import { emojifyText } from '../../_utils/emojifyText'
const REFRESH_MIN_DELAY = 1000 const REFRESH_MIN_DELAY = 1000
@ -284,10 +286,12 @@
computed: { computed: {
pollId: ({ originalStatus }) => originalStatus.poll.id, pollId: ({ originalStatus }) => originalStatus.poll.id,
poll: ({ originalStatus, $polls, pollId }) => $polls[pollId] || originalStatus.poll, poll: ({ originalStatus, $polls, pollId }) => $polls[pollId] || originalStatus.poll,
options: ({ poll }) => poll.options.map(({ title, votes_count: votesCount }) => ({ options: ({ poll, originalStatusEmojis, $autoplayGifs }) => (
title, poll.options.map(({ title, votes_count: votesCount }) => ({
title: emojifyText(escapeHtml(title), originalStatusEmojis, $autoplayGifs),
share: poll.votes_count ? Math.round(votesCount / poll.votes_count * 100) : 0 share: poll.votes_count ? Math.round(votesCount / poll.votes_count * 100) : 0
})), }))
),
votesCount: ({ poll }) => poll.votes_count, votesCount: ({ poll }) => poll.votes_count,
voted: ({ poll }) => poll.voted, voted: ({ poll }) => poll.voted,
multiple: ({ poll }) => poll.multiple, multiple: ({ poll }) => poll.multiple,

View file

@ -7,7 +7,13 @@ import {
getComposePollNthInput, getComposePollNthInput,
composePoll, composePoll,
composePollMultipleChoice, composePollMultipleChoice,
composePollExpiry, composePollAddButton, getComposePollRemoveNthButton, postStatusButton, composeInput, sleep composePollExpiry,
composePollAddButton,
getComposePollRemoveNthButton,
postStatusButton,
composeInput,
sleep,
getNthStatus
} from '../utils' } from '../utils'
import { loginAsFoobar } from '../roles' import { loginAsFoobar } from '../roles'
import { POLL_EXPIRY_DEFAULT } from '../../src/routes/_static/polls' import { POLL_EXPIRY_DEFAULT } from '../../src/routes/_static/polls'
@ -18,6 +24,7 @@ fixture`127-compose-polls.js`
test('Can add and remove poll', async t => { test('Can add and remove poll', async t => {
await loginAsFoobar(t) await loginAsFoobar(t)
await t await t
.expect(getNthStatus(1).exists).ok()
.expect(composePoll.exists).notOk() .expect(composePoll.exists).notOk()
.expect(pollButton.getAttribute('aria-label')).eql('Add poll') .expect(pollButton.getAttribute('aria-label')).eql('Add poll')
.click(pollButton) .click(pollButton)
@ -36,6 +43,7 @@ test('Can add and remove poll', async t => {
test('Can add and remove poll options', async t => { test('Can add and remove poll options', async t => {
await loginAsFoobar(t) await loginAsFoobar(t)
await t await t
.expect(getNthStatus(1).exists).ok()
.expect(composePoll.exists).notOk() .expect(composePoll.exists).notOk()
.expect(pollButton.getAttribute('aria-label')).eql('Add poll') .expect(pollButton.getAttribute('aria-label')).eql('Add poll')
.click(pollButton) .click(pollButton)
@ -73,3 +81,22 @@ test('Can add and remove poll options', async t => {
.expect(getNthStatusPollResult(1, 4).exists).notOk() .expect(getNthStatusPollResult(1, 4).exists).notOk()
.expect(getNthStatusPollVoteCount(1).innerText).eql('0 votes') .expect(getNthStatusPollVoteCount(1).innerText).eql('0 votes')
}) })
test('Properly escapes HTML and emojos in polls', async t => {
await loginAsFoobar(t)
await t
.expect(getNthStatus(1).exists).ok()
.click(pollButton)
.expect(composePoll.exists).ok()
await sleep(1000)
await t
.typeText(composeInput, 'vote vote vote', { paste: true })
.typeText(getComposePollNthInput(1), '&ndash;', { paste: true })
.typeText(getComposePollNthInput(2), ':blobpeek:', { paste: true })
await sleep(1000)
await t
.click(postStatusButton)
.expect(getNthStatusPollResult(1, 1).innerText).contains('&ndash;')
.expect(getNthStatusPollResult(1, 2).find('img').exists).ok()
.expect(getNthStatusPollResult(1, 2).find('img').getAttribute('alt')).eql(':blobpeek:')
})