Skip to content

Commit

Permalink
Add skip recursive parsing is UA client hints and model name empty (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
sanchezzzhak authored Sep 13, 2024
1 parent 2f54d5a commit c6930df
Showing 1 changed file with 15 additions and 1 deletion.
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

0 comments on commit c6930df

Please sign in to comment.