Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Skip recursive device parsing is UA client hints and the model name is empty #7823

Merged
merged 1 commit into from
Sep 13, 2024
Merged
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
16 changes: 15 additions & 1 deletion Parser/Device/AbstractDeviceParser.php
Original file line number Diff line number Diff line change
Expand Up @@ -2153,7 +2153,7 @@ public function parse(): ?array
$deviceModel = $resultClientHint['model'] ?? '';

// is freeze user-agent then restoring the original UA for the device definition
if ('' !== $deviceModel && \preg_match('~Android 10[.\d]*; K(?: Build/|[;)])~i', $this->userAgent)) {
if ('' !== $deviceModel && $this->hasUserAgentClientHintsFragment()) {
$osVersion = $this->clientHints ? $this->clientHints->getOperatingSystemVersion() : '';
$this->setUserAgent((string) \preg_replace(
'(Android 10[.\d]*; K)',
Expand All @@ -2162,6 +2162,10 @@ public function parse(): ?array
));
}

if ('' === $deviceModel && $this->hasUserAgentClientHintsFragment()) {
return $this->getResult();
}

if ('' === $deviceModel && $this->hasDesktopFragment()) {
return $this->getResult();
}
Expand Down Expand Up @@ -2301,6 +2305,16 @@ protected function hasDesktopFragment(): bool
!$this->matchUserAgent($regexExcludeDesktopFragment);
}

/**
* Returns if the parsed UA contains the 'Android 10 K;' or Android 10 K Build/` fragment
*
* @return bool
*/
protected function hasUserAgentClientHintsFragment(): bool
{
return (bool) \preg_match('~Android 10[.\d]*; K(?: Build/|[;)])~i', $this->userAgent);
}

/**
* Resets the stored values
*/
Expand Down
Loading