Fix edge case bug in extractIds

This commit is contained in:
Robert Schäfer 2019-05-21 01:57:41 +02:00
parent 2b03b515e2
commit 2a22aaa907
3 changed files with 10 additions and 3 deletions

View File

@ -2,6 +2,7 @@ import cheerio from 'cheerio'
const ID_REGEX = /\/profile\/([\w\-.!~*'"(),]+)/g
export default function (content) {
if (!content) return []
const $ = cheerio.load(content)
const urls = $('.mention').map((_, el) => {
return $(el).attr('href')

View File

@ -1,6 +1,12 @@
import extractIds from './extractMentions'
import extractIds from '.'
describe('extractIds', () => {
describe('content undefined', () => {
it('returns empty array', () => {
expect(extractIds()).toEqual([])
})
})
describe('extract', () => {
describe('searches through links', () => {
it('ignores links without .mention class', () => {
const content = '<p>Something inspirational about <a href="/profile/u2" target="_blank">@bob-der-baumeister</a> and <a href="/profile/u3" target="_blank">@jenny-rostock</a>.</p>'

View File

@ -1,4 +1,4 @@
import extractIds from './extractMentions'
import extractIds from './extractIds'
const notify = async (resolve, root, args, context, resolveInfo) => {
// extract user ids before xss-middleware removes link classes