Skip to content

Commit

Permalink
fix(logo-favicon): don't resolve roo path as logo
Browse files Browse the repository at this point in the history
  • Loading branch information
Kikobeats committed Nov 26, 2024
1 parent e350568 commit 16cff65
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 1 deletion.
2 changes: 1 addition & 1 deletion packages/metascraper-logo-favicon/src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ const getDomNodeSizes = (domNodes, attr, url) =>
chain(domNodes)
.reduce((acc, domNode) => {
const relativeUrl = domNode.attribs[attr]
if (!relativeUrl) return acc
if (!relativeUrl || relativeUrl === url) return acc
const normalizedUrl = normalizeUrl(url, relativeUrl)
if (!normalizedUrl) return acc
return [
Expand Down
13 changes: 13 additions & 0 deletions packages/metascraper-logo-favicon/test/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,19 @@ test('get the biggest icon possible', async t => {
t.is(metadata.logo, 'https://cdn.microlink.io/logo/favicon-196x196.png')
})

test("don't resolve root path as logo", async t => {
const url = 'https://thisurldoesnotexist.com'
const metascraper = createMetascraper()
const html = createHtml([
'<link rel="icon" type="image/x-icon">',
'<link rel="icon" type="image/x-icon" href="">',
`<link rel="icon" type="image/x-icon" href="${url}">`,
'<link rel="icon" type="image/x-icon" href>'
])
const metadata = await metascraper({ url, html })
t.is(metadata.logo, null)
})

test('get the biggest respecting the format', async t => {
const url = 'https://github.com'
const metascraper = createMetascraper()
Expand Down

0 comments on commit 16cff65

Please sign in to comment.