diff --git a/app/Platform/Services/UserAgentService.php b/app/Platform/Services/UserAgentService.php index b6ff65504c..b462a93984 100644 --- a/app/Platform/Services/UserAgentService.php +++ b/app/Platform/Services/UserAgentService.php @@ -15,6 +15,13 @@ public function decode(string $userAgent): array private function parseUserAgent(string $userAgent): array { + if (empty($userAgent) || $userAgent === '[not provided]') { + return [ + 'client' => 'Unknown', + 'clientVersion' => 'Unknown', + ]; + } + // expected format: / () $userAgentLength = strlen($userAgent); diff --git a/resources/views/pages/ticket/[ticket].blade.php b/resources/views/pages/ticket/[ticket].blade.php index 7123f290d8..4d5cc82589 100644 --- a/resources/views/pages/ticket/[ticket].blade.php +++ b/resources/views/pages/ticket/[ticket].blade.php @@ -121,7 +121,7 @@ return $diff; }); - $userAgentLinks = []; + $clients = []; foreach ($userAgents as $userAgent) { $decoded = $userAgentService->decode($userAgent); $client = $decoded['client']; @@ -131,7 +131,11 @@ if (array_key_exists('clientVariation', $decoded)) { $client .= ' - ' . $decoded['clientVariation']; } - $userAgentLinks[] = "$client"; + $clients[$client][] = $userAgent; + } + $userAgentLinks = []; + foreach ($clients as $client => $agents) { + $userAgentLinks[] = "$client"; } } diff --git a/tests/Feature/Platform/Services/UserAgentServiceTest.php b/tests/Feature/Platform/Services/UserAgentServiceTest.php index 8a2367176a..4b2c6e1a77 100644 --- a/tests/Feature/Platform/Services/UserAgentServiceTest.php +++ b/tests/Feature/Platform/Services/UserAgentServiceTest.php @@ -26,6 +26,16 @@ public function testEmptyUserAgent(): void ], $this->parseUserAgent($userAgent)); } + public function testNotProvidedUserAgent(): void + { + $userAgent = '[not provided]'; + + $this->assertEquals([ + 'client' => 'Unknown', + 'clientVersion' => 'Unknown', + ], $this->parseUserAgent($userAgent)); + } + public function testNoVersionUserAgent(): void { $userAgent = 'MyApp';