From c2d194af1d52c41e1bf46c6cf8729cceceadf52e Mon Sep 17 00:00:00 2001 From: Daniel Supernault Date: Sun, 26 Jul 2020 20:09:45 -0600 Subject: [PATCH] Update webfinger util, fix bug preventing username with dots --- app/Util/Lexer/Nickname.php | 29 ++++++----------------------- 1 file changed, 6 insertions(+), 23 deletions(-) diff --git a/app/Util/Lexer/Nickname.php b/app/Util/Lexer/Nickname.php index 809605abf..c1551ab0f 100644 --- a/app/Util/Lexer/Nickname.php +++ b/app/Util/Lexer/Nickname.php @@ -10,32 +10,15 @@ class Nickname $url = str_replace('acct:', '', $url); } - if (!str_contains($url, '@') && filter_var($url, FILTER_VALIDATE_URL)) { - $parsed = parse_url($url); - $username = str_replace(['/', '\\', '@'], '', $parsed['path']); - - return ['domain' => $parsed['host'], 'username' => $username]; + if(starts_with($url, '@')) { + $url = substr($url, 1); } + $parts = explode('@', $url); - $username = null; - $domain = null; + $username = $parts[0]; + $domain = $parts[1]; - foreach ($parts as $part) { - - // skip empty array slices - if (empty($part)) { - continue; - } - - // if slice contains . assume its a domain - if (str_contains($part, '.')) { - $domain = filter_var($part, FILTER_VALIDATE_URL) ? - parse_url($part, PHP_URL_HOST) : - $part; - } else { - $username = $part; - } - } + if(parse_url(filter_var('https://test.dev', FILTER_VALIDATE_URL), PHP_URL_HOST)) return ['domain' => $domain, 'username' => $username]; }