]> git.mxchange.org Git - friendica.git/commitdiff
Suppress InvalidArgument exceptions handling URLs in Model\Item::containsLink
authorHypolite Petovan <hypolite@mrpetovan.com>
Sat, 5 Nov 2022 22:38:25 +0000 (18:38 -0400)
committerHypolite Petovan <hypolite@mrpetovan.com>
Sun, 6 Nov 2022 00:18:14 +0000 (20:18 -0400)
src/Model/Item.php

index cf7300fc345202e53f6939110f7a1871864575db..b12624aa49a248e5b25a5d8981d17840e3c2cacb 100644 (file)
@@ -3094,11 +3094,20 @@ class Item
        {
                // Make sure that for example site parameters aren't used when testing if the link is contained in the body
                $urlparts = parse_url($url);
-               if (!empty($urlparts)) {
-                       unset($urlparts['query']);
-                       unset($urlparts['fragment']);
+               if (empty($urlparts)) {
+                       return false;
+               }
+
+               unset($urlparts['query']);
+               unset($urlparts['fragment']);
+
+               try {
                        $url = (string)Uri::fromParts($urlparts);
-               } else {
+               } catch (\InvalidArgumentException $e) {
+                       DI::logger()->notice('Invalid URL', ['$url' => $url, '$urlparts' => $urlparts]);
+                       /* See https://github.com/friendica/friendica/issues/12113
+                        * Malformed URLs will result in a Fatal Error
+                        */
                        return false;
                }
 
@@ -3111,12 +3120,14 @@ class Item
                if (strpos($body, $url)) {
                        return true;
                }
+
                foreach ([0, 1, 2] as $size) {
                        if (preg_match('#/photo/.*-' . $size . '\.#ism', $url) &&
                                strpos(preg_replace('#(/photo/.*)-[012]\.#ism', '$1-' . $size . '.', $body), $url)) {
                                return true;
                        }
                }
+
                return false;
        }