Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 8 additions & 1 deletion system/HTTP/UserAgent.php
Original file line number Diff line number Diff line change
Expand Up @@ -317,8 +317,15 @@ protected function setBrowser(): bool
if (is_array($this->config->browsers) && $this->config->browsers !== []) {
foreach ($this->config->browsers as $key => $val) {
if (preg_match('|' . $key . '.*?([0-9\.]+)|i', $this->agent, $match)) {
$version = $match[1];

// Safari's browser version is reported in the Version token.
if ($val === 'Safari' && preg_match('|Version/([0-9\.]+).*?Safari|i', $this->agent, $safariMatch)) {
$version = $safariMatch[1];
}

$this->isBrowser = true;
$this->version = $match[1];
$this->version = $version;
$this->browser = $val;
$this->setMobile();

Expand Down
30 changes: 29 additions & 1 deletion tests/system/HTTP/UserAgentTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -74,10 +74,38 @@ public function testBrowserInfo(): void
{
$this->assertSame('Mac OS X', $this->agent->getPlatform());
$this->assertSame('Safari', $this->agent->getBrowser());
$this->assertSame('533.20.27', $this->agent->getVersion());
$this->assertSame('5.0.4', $this->agent->getVersion());
$this->assertSame('', $this->agent->getRobot());
}

public function testParseModernSafariUsesVersionToken(): void
{
$this->agent->parse('Mozilla/5.0 (Macintosh; Intel Mac OS X 13_2) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/16.3 Safari/605.1.15');

$this->assertSame('Mac OS X', $this->agent->getPlatform());
$this->assertSame('Safari', $this->agent->getBrowser());
$this->assertSame('16.3', $this->agent->getVersion());
}

public function testParseMobileSafariUsesVersionToken(): void
{
$this->agent->parse($this->_mobile_ua);

$this->assertSame('iOS', $this->agent->getPlatform());
$this->assertSame('Safari', $this->agent->getBrowser());
$this->assertSame('4.0.5', $this->agent->getVersion());
$this->assertSame('Apple iPhone', $this->agent->getMobile());
}

public function testParseChromeWithSafariTokenUsesChromeVersion(): void
{
$this->agent->parse('Mozilla/5.0 (Macintosh; Intel Mac OS X 13_2) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/110.0.0.0 Safari/537.36');

$this->assertSame('Mac OS X', $this->agent->getPlatform());
$this->assertSame('Chrome', $this->agent->getBrowser());
$this->assertSame('110.0.0.0', $this->agent->getVersion());
}

public function testParse(): void
{
$newAgent = 'Mozilla/5.0 (Android; Mobile; rv:13.0) Gecko/13.0 Firefox/13.0';
Expand Down
1 change: 1 addition & 0 deletions user_guide_src/source/changelogs/v4.7.4.rst
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ Bugs Fixed
**********

- **Database:** Fixed a bug where ``updateBatch()`` could be called after Query Builder ``where()`` conditions, even though it's not supported. In this situation, now the ``DatabaseException`` is thrown.
- **HTTP:** Fixed a bug where the User Agent library reported Safari's WebKit version instead of the browser version from the ``Version`` token.

See the repo's
`CHANGELOG.md <https://github.com/codeigniter4/CodeIgniter4/blob/develop/CHANGELOG.md>`_
Expand Down
Loading