ash-jc-allen / favicon-fetcher

A Laravel package for fetching favicons from websites.
MIT License
167 stars 13 forks source link

Fix #74 - Returns null when link icon tag doesn't have a href. #77

Closed philipsorensen closed 4 months ago

philipsorensen commented 4 months ago

Returns null instead of attempting to read something that isn't there. Works fine with the provided URL given in the issue #74.

ash-jc-allen commented 4 months ago

Hey @philipsorensen! Thanks for the PR to fix this bug. I've just made a slight change to your approach to fix a potential bug that might have been introduced.

For example, say we have this HTML:

<head>
    <meta charset="utf-8" />
    <title>Dummy title</title>
    <meta name="title" content="Dummy title">
    <meta name="description" content="Dummy title">
    <link rel="icon" type="image/x-icon">
    <link rel="icon" type="image/png" sizes="96x96" href=/favicon-96x96.png>
</head>

Using your proposed approach, it would still grab the first link and then would return null because it doesn't have an href attribute. But there's still a valid icon in there that has a href set.

So I've updated the code so we'll only attempt to read the link tag from the HTML if it has a href attribute set.

Huge thanks for this though because you gave me a much-needed nudge to get this merged and fixed! 😄