diff --git a/src/services/status_parser/status_parser.js b/src/services/status_parser/status_parser.js index f1d113dd..900cd56e 100644 --- a/src/services/status_parser/status_parser.js +++ b/src/services/status_parser/status_parser.js @@ -4,7 +4,7 @@ export const removeAttachmentLinks = (html) => { return sanitize(html, { allowedTags: 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/) }) } diff --git a/test/unit/specs/services/status_parser/status_parses.spec.js b/test/unit/specs/services/status_parser/status_parses.spec.js index e6d185f8..65808d84 100644 --- a/test/unit/specs/services/status_parser/status_parses.spec.js +++ b/test/unit/specs/services/status_parser/status_parses.spec.js @@ -4,8 +4,14 @@ import { removeAttachmentLinks } from '../../../../../src/services/status_parser describe('statusParser.removeAttachmentLinks', () => { const exampleWithoutAttachmentLinks = '
@dwmatiz
' + it('removes attachment links', () => { const parsed = removeAttachmentLinks(example) expect(parsed).to.eql(exampleWithoutAttachmentLinks) }) + + it('works when the class is empty', () => { + const parsed = removeAttachmentLinks('') + expect(parsed).to.eql('') + }) })