Skip to content

Commit

Permalink
Improves detection for client hints fragment
Browse files Browse the repository at this point in the history
  • Loading branch information
liviuconcioiu committed Oct 3, 2024
1 parent e6456a1 commit 7ff422d
Show file tree
Hide file tree
Showing 2 changed files with 81 additions and 2 deletions.
4 changes: 2 additions & 2 deletions Parser/Device/AbstractDeviceParser.php
Original file line number Diff line number Diff line change
Expand Up @@ -2180,7 +2180,7 @@ public function parse(): ?array
if ('' !== $deviceModel && $this->hasUserAgentClientHintsFragment()) {
$osVersion = $this->clientHints ? $this->clientHints->getOperatingSystemVersion() : '';
$this->setUserAgent((string) \preg_replace(
'(Android 10[.\d]*; K)',
'(Android (?:10[.\d]*; K|1[1-5]))',
\sprintf('Android %s; %s', '' !== $osVersion ? $osVersion : '10', $deviceModel),
$this->userAgent
));
Expand Down Expand Up @@ -2345,7 +2345,7 @@ protected function hasDesktopFragment(): bool
*/
protected function hasUserAgentClientHintsFragment(): bool
{
return (bool) \preg_match('~Android 10[.\d]*; K(?: Build/|[;)])~i', $this->userAgent);
return (bool) \preg_match('~Android (?:10[.\d]*; K(?: Build/|[;)])|1[1-5]\)) AppleWebKit~i', $this->userAgent);
}

/**
Expand Down
79 changes: 79 additions & 0 deletions Tests/fixtures/clienthints.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3605,3 +3605,82 @@
model: HK1RBOX-X4
os_family: Android
browser_family: Chrome
-
user_agent: Mozilla/5.0 (Linux; Android 11) AppleWebKit/537.36 (KHTML, like Gecko) Version/4.0 Chrome/126.0.0.0 Mobile DuckDuckGo/5 Safari/537.36
headers:
Sec-CH-UA: '"Not/A)Brand";v="8.0.0.0", "Chromium";v="126.0.6478.186", "DuckDuckGo";v="126.0.6478.186"'
Sec-CH-UA-Platform: "Android"
Sec-CH-UA-Mobile: "?1"
Sec-CH-UA-Full-Version: "126.0.6478.186"
Sec-CH-UA-Platform-Version: "11.0.0"
Sec-CH-UA-Model: "Nokia 7.2"
http-x-requested-with: "com.duckduckgo.mobile.android"
os:
name: Android
version: 11.0.0
platform: ""
client:
type: browser
name: DuckDuckGo Privacy Browser
version: ""
engine: Blink
engine_version: 126.0.0.0
device:
type: smartphone
brand: Nokia
model: "7.2"
os_family: Android
browser_family: Chrome
-
user_agent: Mozilla/5.0 (Linux; Android 13) AppleWebKit/537.36 (KHTML, like Gecko) Version/4.0 Chrome/127.0.0.0 Mobile DuckDuckGo/5 Safari/537.36
headers:
Sec-CH-UA: '"Not)A;Brand";v="99.0.0.0", "DuckDuckGo";v="127.0.6533.64", "Chromium";v="127.0.6533.64"'
Sec-CH-UA-Platform: "Android"
Sec-CH-UA-Mobile: "?1"
Sec-CH-UA-Full-Version: "127.0.6533.64"
Sec-CH-UA-Platform-Version: "13.0.0"
Sec-CH-UA-Model: "SM-G781V"
http-x-requested-with: "com.duckduckgo.mobile.android"
os:
name: Android
version: 13.0.0
platform: ""
client:
type: browser
name: DuckDuckGo Privacy Browser
version: ""
engine: Blink
engine_version: 127.0.0.0
device:
type: smartphone
brand: Samsung
model: Galaxy S20 FE 5G
os_family: Android
browser_family: Chrome
-
user_agent: Mozilla/5.0 (Linux; Android 14) AppleWebKit/537.36 (KHTML, like Gecko) Version/4.0 Chrome/128.0.0.0 Mobile DuckDuckGo/5 Safari/537.36
headers:
Sec-CH-UA: '"Chromium";v="128.0.6613.146", "Not;A=Brand";v="24.0.0.0", "DuckDuckGo";v="128.0.6613.146"'
Sec-CH-UA-Platform: "Android"
Sec-CH-UA-Mobile: "?1"
Sec-CH-UA-Full-Version: "128.0.6613.146"
Sec-CH-UA-Platform-Version: "14.0.0"
Sec-CH-UA-Model: "SM-A137F"
Sec-CH-UA-Form-Factors: "Mobile"
http-x-requested-with: "com.duckduckgo.mobile.android"
os:
name: Android
version: 14.0.0
platform: ""
client:
type: browser
name: DuckDuckGo Privacy Browser
version: ""
engine: Blink
engine_version: 128.0.0.0
device:
type: smartphone
brand: Samsung
model: Galaxy A13
os_family: Android
browser_family: Chrome

0 comments on commit 7ff422d

Please sign in to comment.