From 1321a52f1575f8f80e5410980e7d3eb1a29d1fa3 Mon Sep 17 00:00:00 2001 From: Hypolite Petovan Date: Thu, 2 Dec 2021 08:02:26 -0500 Subject: [PATCH 1/2] Reformat Probe::getWebfingerArray --- src/Network/Probe.php | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/src/Network/Probe.php b/src/Network/Probe.php index ee36651d6d..e9e8478524 100644 --- a/src/Network/Probe.php +++ b/src/Network/Probe.php @@ -508,16 +508,17 @@ class Probe * Get webfinger data from a given URI * * @param string $uri - * @return array Webfinger array + * @return array + * @throws HTTPException\InternalServerErrorException */ - private static function getWebfingerArray(string $uri) + private static function getWebfingerArray(string $uri): array { $parts = parse_url($uri); if (!empty($parts['scheme']) && !empty($parts['host'])) { $host = $parts['host']; if (!empty($parts['port'])) { - $host .= ':'.$parts['port']; + $host .= ':' . $parts['port']; } $baseurl = $parts['scheme'] . '://' . $host; @@ -525,12 +526,12 @@ class Probe $nick = ''; $addr = ''; - $path_parts = explode("/", trim($parts['path'] ?? '', "/")); + $path_parts = explode('/', trim($parts['path'] ?? '', '/')); if (!empty($path_parts)) { $nick = ltrim(end($path_parts), '@'); // When the last part of the URI is numeric then it is most likely an ID and not a nick name if (!is_numeric($nick)) { - $addr = $nick."@".$host; + $addr = $nick . '@' . $host; } else { $nick = ''; } @@ -543,11 +544,11 @@ class Probe if (empty($webfinger) && empty($lrdd)) { while (empty($lrdd) && empty($webfinger) && (sizeof($path_parts) > 1)) { - $host .= "/".array_shift($path_parts); + $host .= '/' . array_shift($path_parts); $baseurl = $parts['scheme'] . '://' . $host; if (!empty($nick)) { - $addr = $nick."@".$host; + $addr = $nick . '@' . $host; } $webfinger = self::getWebfinger($parts['scheme'] . '://' . $host . self::WEBFINGER, 'application/jrd+json', $uri, $addr); From f409bd70346c221e9692d43937462f73e6bc090e Mon Sep 17 00:00:00 2001 From: Hypolite Petovan Date: Thu, 2 Dec 2021 08:03:38 -0500 Subject: [PATCH 2/2] Remove all-numeric usernames condition - False negatives aren't recoverable --- src/Network/Probe.php | 7 +------ 1 file changed, 1 insertion(+), 6 deletions(-) diff --git a/src/Network/Probe.php b/src/Network/Probe.php index e9e8478524..d8c1a91530 100644 --- a/src/Network/Probe.php +++ b/src/Network/Probe.php @@ -529,12 +529,7 @@ class Probe $path_parts = explode('/', trim($parts['path'] ?? '', '/')); if (!empty($path_parts)) { $nick = ltrim(end($path_parts), '@'); - // When the last part of the URI is numeric then it is most likely an ID and not a nick name - if (!is_numeric($nick)) { - $addr = $nick . '@' . $host; - } else { - $nick = ''; - } + $addr = $nick . '@' . $host; } $webfinger = self::getWebfinger($parts['scheme'] . '://' . $host . self::WEBFINGER, 'application/jrd+json', $uri, $addr);