Skip to content

Commit

Permalink
Ignore invalid URLs
Browse files Browse the repository at this point in the history
  • Loading branch information
Kikobeats committed Jul 5, 2018
1 parent d2a1993 commit 08f8529
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 6 deletions.
2 changes: 2 additions & 0 deletions __snapshots__/index.js.snap-shot
Original file line number Diff line number Diff line change
Expand Up @@ -632,3 +632,5 @@ exports['${tag} (${attributeName}) 27'] = [
}
]

exports['ignore invalid URLs 1'] = []

14 changes: 8 additions & 6 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,12 +41,14 @@ const includes = (collection, fn) => findIndex(collection, fn) !== -1

const getLink = ({ url, el, attribute }) => {
const attr = get(el, `attribs.${attribute}`, '')
return isEmpty(attr)
? null
: Object.assign({
url: attr,
normalizedUrl: getUrl(url, attr)
})
if (isEmpty(attr)) return null

try {
const normalizedUrl = getUrl(url, attr)
return { url: attr, normalizedUrl }
} catch (err) {
return null
}
}

const getLinksByAttribute = ({ selector, attribute, url, whitelist }) => {
Expand Down
8 changes: 8 additions & 0 deletions test/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,14 @@ describe('html links', () => {

snapshot(getLinks({ html }))
})

it('ignore invalid URLs', () => {
const html = generateHtml({
urls: ['http://']
})

snapshot(getLinks({ html }))
})
})

describe('selectors supported', () => {
Expand Down

0 comments on commit 08f8529

Please sign in to comment.