From 7ff422df8ffc2652bf1fe2602b1ba53cd5e8751e Mon Sep 17 00:00:00 2001 From: Liviu-Mihail Concioiu Date: Thu, 3 Oct 2024 05:16:58 +0200 Subject: [PATCH] Improves detection for client hints fragment --- Parser/Device/AbstractDeviceParser.php | 4 +- Tests/fixtures/clienthints.yml | 79 ++++++++++++++++++++++++++ 2 files changed, 81 insertions(+), 2 deletions(-) diff --git a/Parser/Device/AbstractDeviceParser.php b/Parser/Device/AbstractDeviceParser.php index a7456676fe..578204c3b4 100644 --- a/Parser/Device/AbstractDeviceParser.php +++ b/Parser/Device/AbstractDeviceParser.php @@ -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 )); @@ -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); } /** diff --git a/Tests/fixtures/clienthints.yml b/Tests/fixtures/clienthints.yml index 432e559f52..25f160785f 100644 --- a/Tests/fixtures/clienthints.yml +++ b/Tests/fixtures/clienthints.yml @@ -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