Don't break status parsing when link class is missing.

This commit is contained in:
Roger Braun 2016-11-13 00:08:03 +01:00
parent 43eb9c022d
commit ee009f63dd
2 changed files with 7 additions and 1 deletions

View file

@ -4,7 +4,7 @@ export const removeAttachmentLinks = (html) => {
return sanitize(html, { return sanitize(html, {
allowedTags: false, allowedTags: false,
allowedAttributes: false, allowedAttributes: false,
exclusiveFilter: ({ tag, attribs }) => tag === 'a' && attribs.class.match(/attachment/) exclusiveFilter: ({ tag, attribs }) => tag === 'a' && typeof attribs.class === 'string' && attribs.class.match(/attachment/)
}) })
} }

View file

@ -4,8 +4,14 @@ import { removeAttachmentLinks } from '../../../../../src/services/status_parser
describe('statusParser.removeAttachmentLinks', () => { describe('statusParser.removeAttachmentLinks', () => {
const exampleWithoutAttachmentLinks = '<div class="status-content">@<a href="https://sealion.club/user/4" class="h-card mention" title="dewoo">dwmatiz</a> </div>' const exampleWithoutAttachmentLinks = '<div class="status-content">@<a href="https://sealion.club/user/4" class="h-card mention" title="dewoo">dwmatiz</a> </div>'
it('removes attachment links', () => { it('removes attachment links', () => {
const parsed = removeAttachmentLinks(example) const parsed = removeAttachmentLinks(example)
expect(parsed).to.eql(exampleWithoutAttachmentLinks) expect(parsed).to.eql(exampleWithoutAttachmentLinks)
}) })
it('works when the class is empty', () => {
const parsed = removeAttachmentLinks('<a></a>')
expect(parsed).to.eql('<a></a>')
})
}) })