From ec959939173b752e54551219132dfcbada1979b9 Mon Sep 17 00:00:00 2001 From: Stefan Giehl Date: Fri, 10 Jun 2022 10:31:21 +0200 Subject: [PATCH] Fix version truncation for client hints (#7138) --- Parser/Client/Browser.php | 2 +- Parser/OperatingSystem.php | 2 +- Tests/DeviceDetectorTest.php | 25 +++++++++++++++++++++++++ 3 files changed, 27 insertions(+), 2 deletions(-) diff --git a/Parser/Client/Browser.php b/Parser/Client/Browser.php index 992ce69b73..5408162a93 100644 --- a/Parser/Client/Browser.php +++ b/Parser/Client/Browser.php @@ -817,7 +817,7 @@ protected function parseBrowserFromClientHints(): array return [ 'name' => $name, 'short_name' => $short, - 'version' => $version, + 'version' => $this->buildVersion($version, []), ]; } diff --git a/Parser/OperatingSystem.php b/Parser/OperatingSystem.php index ef12578ae0..9b5005ab1f 100644 --- a/Parser/OperatingSystem.php +++ b/Parser/OperatingSystem.php @@ -439,7 +439,7 @@ protected function parseOsFromClientHints(): array return [ 'name' => $name, 'short_name' => $short, - 'version' => $version, + 'version' => $this->buildVersion($version, []), ]; } diff --git a/Tests/DeviceDetectorTest.php b/Tests/DeviceDetectorTest.php index 5fb2948ae2..0e3703c060 100644 --- a/Tests/DeviceDetectorTest.php +++ b/Tests/DeviceDetectorTest.php @@ -290,6 +290,31 @@ public function getVersionTruncationFixtures(): array ]; } + public function testVersionTruncationForClientHints(): void + { + AbstractParser::setVersionTruncation(AbstractParser::VERSION_TRUNCATION_MINOR); + $dd = new DeviceDetector(); + $dd->setClientHints(new ClientHints( + 'Galaxy 4', + 'Android', + '8.0.5', + '98.0.14335.105', + [ + ['brand' => ' Not A;Brand', 'version' => '99.0.0.0'], + ['brand' => 'Chromium', 'version' => '98.0.14335.105'], + ['brand' => 'Chrome', 'version' => '98.0.14335.105'], + ], + true, + '', + '', + '' + )); + $dd->parse(); + $this->assertEquals('8.0', $dd->getOs('version')); + $this->assertEquals('98.0', $dd->getClient('version')); + AbstractParser::setVersionTruncation(AbstractParser::VERSION_TRUNCATION_NONE); + } + /** * @dataProvider getBotFixtures */