Skip to content

Commit

Permalink
Fix version truncation for client hints (#7138)
Browse files Browse the repository at this point in the history
  • Loading branch information
sgiehl authored Jun 10, 2022
1 parent 829935d commit ec95993
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 2 deletions.
2 changes: 1 addition & 1 deletion Parser/Client/Browser.php
Original file line number Diff line number Diff line change
Expand Up @@ -817,7 +817,7 @@ protected function parseBrowserFromClientHints(): array
return [
'name' => $name,
'short_name' => $short,
'version' => $version,
'version' => $this->buildVersion($version, []),
];
}

Expand Down
2 changes: 1 addition & 1 deletion Parser/OperatingSystem.php
Original file line number Diff line number Diff line change
Expand Up @@ -439,7 +439,7 @@ protected function parseOsFromClientHints(): array
return [
'name' => $name,
'short_name' => $short,
'version' => $version,
'version' => $this->buildVersion($version, []),
];
}

Expand Down
25 changes: 25 additions & 0 deletions Tests/DeviceDetectorTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
*/
Expand Down

0 comments on commit ec95993

Please sign in to comment.