Merge pull request #11057 from MrPetovan/bug/10971-probe-numeric-username

Remove all-numeric usernames condition
This commit is contained in:
Tobias Diekershoff 2021-12-02 14:59:22 +01:00 committed by GitHub
commit b780f29765
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -508,16 +508,17 @@ class Probe
* Get webfinger data from a given URI * Get webfinger data from a given URI
* *
* @param string $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); $parts = parse_url($uri);
if (!empty($parts['scheme']) && !empty($parts['host'])) { if (!empty($parts['scheme']) && !empty($parts['host'])) {
$host = $parts['host']; $host = $parts['host'];
if (!empty($parts['port'])) { if (!empty($parts['port'])) {
$host .= ':'.$parts['port']; $host .= ':' . $parts['port'];
} }
$baseurl = $parts['scheme'] . '://' . $host; $baseurl = $parts['scheme'] . '://' . $host;
@ -525,15 +526,10 @@ class Probe
$nick = ''; $nick = '';
$addr = ''; $addr = '';
$path_parts = explode("/", trim($parts['path'] ?? '', "/")); $path_parts = explode('/', trim($parts['path'] ?? '', '/'));
if (!empty($path_parts)) { if (!empty($path_parts)) {
$nick = ltrim(end($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 $addr = $nick . '@' . $host;
if (!is_numeric($nick)) {
$addr = $nick."@".$host;
} else {
$nick = '';
}
} }
$webfinger = self::getWebfinger($parts['scheme'] . '://' . $host . self::WEBFINGER, 'application/jrd+json', $uri, $addr); $webfinger = self::getWebfinger($parts['scheme'] . '://' . $host . self::WEBFINGER, 'application/jrd+json', $uri, $addr);
@ -543,11 +539,11 @@ class Probe
if (empty($webfinger) && empty($lrdd)) { if (empty($webfinger) && empty($lrdd)) {
while (empty($lrdd) && empty($webfinger) && (sizeof($path_parts) > 1)) { while (empty($lrdd) && empty($webfinger) && (sizeof($path_parts) > 1)) {
$host .= "/".array_shift($path_parts); $host .= '/' . array_shift($path_parts);
$baseurl = $parts['scheme'] . '://' . $host; $baseurl = $parts['scheme'] . '://' . $host;
if (!empty($nick)) { if (!empty($nick)) {
$addr = $nick."@".$host; $addr = $nick . '@' . $host;
} }
$webfinger = self::getWebfinger($parts['scheme'] . '://' . $host . self::WEBFINGER, 'application/jrd+json', $uri, $addr); $webfinger = self::getWebfinger($parts['scheme'] . '://' . $host . self::WEBFINGER, 'application/jrd+json', $uri, $addr);