Skip to content

Commit

Permalink
Merge pull request #745 from microlinkhq/next
Browse files Browse the repository at this point in the history
fix(logo-favicon): ensure body is present
  • Loading branch information
Kikobeats authored Feb 3, 2025
2 parents d64004a + a2ecb27 commit 1959e41
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 1 deletion.
3 changes: 2 additions & 1 deletion packages/metascraper-logo-favicon/src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,8 @@ const defaultResolveFaviconUrl = async (faviconUrl, contentTypes, gotOpts) => {
return undefined
}

if (contentTypes && response.body.toString()[0] === '<') {
// 60 is the ASCII code for '<'
if (contentTypes && (!response.body || response.body[0] === 60)) {
return undefined
}

Expand Down
16 changes: 16 additions & 0 deletions packages/metascraper-logo-favicon/test/resolve-favicon-url.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
'use strict'

const test = require('ava')
const got = require('got')

const { resolveFaviconUrl } = require('..')
const { runServer } = require('./helpers')
Expand All @@ -24,6 +25,21 @@ test('undefined if content type is not expected', async t => {
t.is(await resolveFaviconUrl(toUrl(url, 'favicon.ico'), []), undefined)
})

test('undefined if body is not present', async t => {
const url = await runServer(t, async ({ res }) => {
const stream = got.stream(
'https://cdn.microlink.io/file-examples/sample-big.jpg'
)
stream.pipe(res)
setTimeout(() => res.destroy(), 100)
})

t.is(
await resolveFaviconUrl(url, ['jpg', ['image/jpeg']], { retry: 0 }),
undefined
)
})

test('undefined if body is not the expected according to content type', async t => {
const url = await runServer(t, async ({ res }) => {
res.setHeader('content-type', 'image/x-icon')
Expand Down

0 comments on commit 1959e41

Please sign in to comment.