]> git.mxchange.org Git - friendica.git/commitdiff
Handle exception on "head" / missing class variable added
authorMichael <heluecht@pirati.ca>
Tue, 11 Apr 2023 02:11:39 +0000 (02:11 +0000)
committerMichael <heluecht@pirati.ca>
Tue, 11 Apr 2023 02:11:39 +0000 (02:11 +0000)
src/Content/OEmbed.php
src/Object/OEmbed.php
src/Util/Network.php
src/Util/ParseUrl.php

index c113110662351f44d2328807cca1920d0d682c9d..7afdfac35c35361e230fcb3b235a0c54eb21a300 100644 (file)
@@ -334,8 +334,8 @@ class OEmbed
                        $html_text = mb_convert_encoding($text, 'HTML-ENTITIES', mb_detect_encoding($text));
 
                        // If it doesn't parse at all, just return the text.
-                       $dom = @DOMDocument::loadHTML($html_text);
-                       if (!$dom) {
+                       $dom = new DOMDocument();
+                       if (!@$dom->loadHTML($html_text)) {
                                return $text;
                        }
                        $xpath = new DOMXPath($dom);
index 2511a0f7586c1cb0a100a8be3cc472dad06f8c5e..3f53f48cd18d5287af17d41eea02eb17638f51ec 100644 (file)
@@ -34,6 +34,7 @@ class OEmbed
 
        public $type             = '';
        public $title            = '';
+       public $description      = '';
        public $author_name      = '';
        public $author_url       = '';
        public $provider_name    = '';
index e02767be4a950acc7c8c646443ce1f4531cfc9fc..f7ceab5433b217bbc33c2ccb98770cbaf40020f1 100644 (file)
@@ -79,11 +79,19 @@ class Network
 
                if (in_array(parse_url($url, PHP_URL_SCHEME), ['https', 'http'])) {
                        $options = [HttpClientOptions::VERIFY => true, HttpClientOptions::TIMEOUT => $xrd_timeout];
-                       $curlResult = DI::httpClient()->head($url, $options);
+                       try {
+                               $curlResult = DI::httpClient()->head($url, $options);
+                       } catch (\Exception $e) {
+                               return false;
+                       }
 
                        // Workaround for systems that can't handle a HEAD request. Don't retry on timeouts.
                        if (!$curlResult->isSuccess() && ($curlResult->getReturnCode() >= 400) && !in_array($curlResult->getReturnCode(), [408, 504])) {
-                               $curlResult = DI::httpClient()->get($url, HttpClientAccept::DEFAULT, $options);
+                               try {
+                                       $curlResult = DI::httpClient()->get($url, HttpClientAccept::DEFAULT, $options);
+                               } catch (\Exception $e) {
+                                       return false;
+                               }
                        }
 
                        if (!$curlResult->isSuccess()) {
index 33828848391410a843475080905a30d41af1eaa7..79f427a654df4b5f672bc52f3470ebe01deb2b5b 100644 (file)
@@ -70,7 +70,12 @@ class ParseUrl
                        $options = [];
                }
 
-               $curlResult = DI::httpClient()->head($url, array_merge([HttpClientOptions::ACCEPT_CONTENT => $accept], $options));
+               try {
+                       $curlResult = DI::httpClient()->head($url, array_merge([HttpClientOptions::ACCEPT_CONTENT => $accept], $options));
+               } catch (\Exception $e) {
+                       DI::logger()->debug('Got exception', ['url' => $url, 'message' => $e->getMessage()]);
+                       return [];
+               }
 
                // Workaround for systems that can't handle a HEAD request. Don't retry on timeouts.
                if (!$curlResult->isSuccess() && ($curlResult->getReturnCode() >= 400) && !in_array($curlResult->getReturnCode(), [408, 504])) {