]> git.mxchange.org Git - friendica.git/commitdiff
Catch exceptions in Model\Gserver::cleanURL
authorHypolite Petovan <hypolite@mrpetovan.com>
Fri, 16 Dec 2022 15:15:43 +0000 (10:15 -0500)
committerHypolite Petovan <hypolite@mrpetovan.com>
Fri, 16 Dec 2022 22:39:40 +0000 (17:39 -0500)
- Address https://github.com/friendica/friendica/issues/11992#issuecomment-1354393419

src/Model/GServer.php

index a128060f4c1694388b8c5f2b83c83856155c8a31..e93c347627d5bd269f2b6a72418c71a50ab95acc 100644 (file)
@@ -314,25 +314,20 @@ class GServer
        /**
         * Remove unwanted content from the given URL
         *
-        * @param string $url
+        * @param string $dirtyUrl
         *
         * @return string cleaned URL
+        * @throws Exception
         */
-       public static function cleanURL(string $url): string
+       public static function cleanURL(string $dirtyUrl): string
        {
-               $url = trim($url, '/');
-               $url = str_replace('/index.php', '', $url);
-
-               $urlparts = parse_url($url);
-               if (empty($urlparts)) {
+               try {
+                       $url = str_replace('/index.php', '', trim($dirtyUrl, '/'));
+                       return (string)(new Uri($url))->withUserInfo('')->withQuery('')->withFragment('');
+               } catch (\Throwable $e) {
+                       Logger::warning('Invalid URL', ['dirtyUrl' => $dirtyUrl, 'url' => $url]);
                        return '';
                }
-
-               unset($urlparts['user']);
-               unset($urlparts['pass']);
-               unset($urlparts['query']);
-               unset($urlparts['fragment']);
-               return (string)Uri::fromParts($urlparts);
        }
 
        /**