Skip to content

Commit a144c25

Browse files
committed
Ensured html decoding of og:image urls
Related to #5
1 parent 9788330 commit a144c25

File tree

2 files changed

+25
-1
lines changed

2 files changed

+25
-1
lines changed

app/Rss/PostThumbnailFetcher.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ protected function getThumbLinkFromUrl(string $url): string
7979
return '';
8080
}
8181

82-
$link = $linkMatches[1];
82+
$link = html_entity_decode($linkMatches[1]);
8383

8484
if (!str_starts_with($link, 'https://') && !str_starts_with($link, 'http://')) {
8585
return '';

tests/Feature/PostThumbnailFetcherTest.php

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,4 +40,28 @@ public function test_successful_fetch()
4040

4141
unlink($expectedPath);
4242
}
43+
44+
public function test_html_encoding_in_opengraph_url_is_decoded()
45+
{
46+
$imageData = base64_decode('iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAYAAAAfFcSJAAAACklEQVR4nGMAAQAABQABDQottAAAAABJRU5ErkJggg==');
47+
Http::fake([
48+
'example.com/*' => Http::response(<<<END
49+
<html>
50+
<head>
51+
<meta property="og:image" content="https://exampleb.com/image.png?a=b&amp;c=d">
52+
</head>
53+
</html>
54+
END),
55+
'https://exampleb.com/image.png?a=b&c=d' => Http::response($imageData),
56+
'exampleb.com/*' => Http::response('', 404),
57+
]);
58+
$post = Post::factory()->create(['url' => 'http://example.com/cats']);
59+
60+
$fetcher = new PostThumbnailFetcher();
61+
$result = $fetcher->fetchAndStoreForPost($post);
62+
$this->assertTrue($result);
63+
64+
$expectedPath = storage_path("app/public/thumbs/{$post->feed_id}/{$post->id}.png");
65+
unlink($expectedPath);
66+
}
4367
}

0 commit comments

Comments
 (0)