From 695e3d8b611364ce864a71467eebd666de2d9c19 Mon Sep 17 00:00:00 2001 From: Michael Date: Wed, 11 May 2022 06:55:02 +0000 Subject: [PATCH 1/4] Simplifiy the split --- src/Util/Network.php | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/Util/Network.php b/src/Util/Network.php index bc374c2bcc..cdcb39a496 100644 --- a/src/Util/Network.php +++ b/src/Util/Network.php @@ -475,10 +475,10 @@ class Network $parts['host'] = idn_to_ascii($parts['host']); $uri = self::unparseURL($parts); } elseif (strstr($uri, '@')) { - $host = idn_to_ascii(substr($uri, strpos($uri, '@') + 1)); - $nick = substr($uri, 0, strpos($uri, '@')); - - $uri = $nick . '@' . $host; + $parts = explode('@', $uri); + if (count($parts) == 2) { + $uri = $parts[0] . '@' . idn_to_ascii($parts[1]); + } } return $uri; From 020ba7a4eddb94250c530da5e3cd85ffee8101bd Mon Sep 17 00:00:00 2001 From: Michael Date: Wed, 11 May 2022 06:58:26 +0000 Subject: [PATCH 2/4] The function is now usable for all formats --- src/Util/Network.php | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/Util/Network.php b/src/Util/Network.php index cdcb39a496..7d935d55f0 100644 --- a/src/Util/Network.php +++ b/src/Util/Network.php @@ -474,10 +474,12 @@ class Network if (!empty($parts['scheme']) && !empty($parts['host'])) { $parts['host'] = idn_to_ascii($parts['host']); $uri = self::unparseURL($parts); - } elseif (strstr($uri, '@')) { + } else { $parts = explode('@', $uri); if (count($parts) == 2) { $uri = $parts[0] . '@' . idn_to_ascii($parts[1]); + } else { + $uri = idn_to_ascii($uri); } } From 34f594137e2c13ec9b88a6b799d7c62a667cc979 Mon Sep 17 00:00:00 2001 From: Michael Date: Wed, 11 May 2022 10:56:44 +0000 Subject: [PATCH 3/4] Movwe the conversion after the cleaning --- src/Network/Probe.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Network/Probe.php b/src/Network/Probe.php index 70ab396fed..c5ecf96ed3 100644 --- a/src/Network/Probe.php +++ b/src/Network/Probe.php @@ -65,11 +65,11 @@ class Probe */ public static function cleanURI(string $rawUri): string { - $rawUri = Network::convertToIdn($rawUri); - // At first remove leading and trailing junk $rawUri = trim($rawUri, "@#?:/ \t\n\r\0\x0B"); + $rawUri = Network::convertToIdn($rawUri); + $uri = new Uri($rawUri); if (!$uri->getScheme()) { return $uri->__toString(); From 0f0b649e8d92a70c9933ec6022e2bce716c413f7 Mon Sep 17 00:00:00 2001 From: Michael Date: Wed, 11 May 2022 11:06:14 +0000 Subject: [PATCH 4/4] Replace unparse function --- src/Util/Network.php | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/Util/Network.php b/src/Util/Network.php index 7d935d55f0..af4d18b4ab 100644 --- a/src/Util/Network.php +++ b/src/Util/Network.php @@ -26,6 +26,7 @@ use Friendica\Core\Logger; use Friendica\DI; use Friendica\Model\Contact; use Friendica\Network\HTTPException\NotModifiedException; +use GuzzleHttp\Psr7\Uri; class Network { @@ -436,7 +437,7 @@ class Network * @param array $parsed URL parts * * @return string The glued URL. - * @deprecated since version 2021.12, use a UriInterface object like GuzzleHttp\Psr7\Uri instead + * @deprecated since version 2021.12, use GuzzleHttp\Psr7\Uri::fromParts($parts) instead */ public static function unparseURL(array $parsed) { @@ -473,7 +474,7 @@ class Network $parts = parse_url($uri); if (!empty($parts['scheme']) && !empty($parts['host'])) { $parts['host'] = idn_to_ascii($parts['host']); - $uri = self::unparseURL($parts); + $uri = Uri::fromParts($parts); } else { $parts = explode('@', $uri); if (count($parts) == 2) {