From 499a876801daa80a63539ac347c4e438a0014e36 Mon Sep 17 00:00:00 2001 From: Jesus Ortega Date: Sat, 17 Apr 2021 13:13:57 +0200 Subject: [PATCH] Prevent accessing explode results when empty Related to Generate screenshots for links #18 --- app/Helper/HtmlMeta.php | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/app/Helper/HtmlMeta.php b/app/Helper/HtmlMeta.php index fc45ca23..46f47829 100644 --- a/app/Helper/HtmlMeta.php +++ b/app/Helper/HtmlMeta.php @@ -67,13 +67,14 @@ class HtmlMeta ?? null; //Edge case of Youtube only (because of Youtube EU cookie consent) - if (str_contains($url, 'youtube')) { - if (is_null($thumbnail)) { - //Formula based on https://stackoverflow.com/a/2068371 - $explode = explode('v=', $url); - //https://img.youtube.com/vi/[video-id]/mqdefault.jpg - $thumbnail = 'https://img.youtube.com/vi/'.$explode[1].'/mqdefault.jpg'; - } + if (str_contains($url, 'youtube') + && str_contains($url, 'v=') + && is_null($thumbnail) + ) { + //Formula based on https://stackoverflow.com/a/2068371 + $explode = explode('v=', $url); + //https://img.youtube.com/vi/[video-id]/mqdefault.jpg + $thumbnail = 'https://img.youtube.com/vi/' . $explode[1] . '/mqdefault.jpg'; } return [