Skip to content

Commit

Permalink
Improve regexes (#7900)
Browse files Browse the repository at this point in the history
  • Loading branch information
liviuconcioiu authored Nov 5, 2024
1 parent f134462 commit bedd142
Show file tree
Hide file tree
Showing 13 changed files with 1,392 additions and 1,392 deletions.
8 changes: 4 additions & 4 deletions DeviceDetector.php
Original file line number Diff line number Diff line change
Expand Up @@ -776,7 +776,7 @@ protected function getOsAttribute(string $attr): string
*/
protected function hasAndroidTableFragment(): bool
{
$regex = 'Android( [\.0-9]+)?; Tablet;|Tablet(?! PC)|.*\-tablet$';
$regex = 'Android( [.0-9]+)?; Tablet;|Tablet(?! PC)|.*\-tablet$';

return !!$this->matchUserAgent($regex);
}
Expand All @@ -788,7 +788,7 @@ protected function hasAndroidTableFragment(): bool
*/
protected function hasAndroidMobileFragment(): bool
{
$regex = 'Android( [\.0-9]+)?; Mobile;|.*\-mobile$';
$regex = 'Android( [.0-9]+)?; Mobile;|.*\-mobile$';

return !!$this->matchUserAgent($regex);
}
Expand All @@ -800,7 +800,7 @@ protected function hasAndroidMobileFragment(): bool
*/
protected function hasAndroidVRFragment(): bool
{
$regex = 'Android( [\.0-9]+)?; Mobile VR;| VR ';
$regex = 'Android( [.0-9]+)?; Mobile VR;| VR ';

return !!$this->matchUserAgent($regex);
}
Expand Down Expand Up @@ -959,7 +959,7 @@ protected function parseDevice(): void
* a detected browser, but can still be detected. So we check the useragent for Chrome instead.
*/
if (null === $this->device && 'Android' === $osFamily
&& $this->matchUserAgent('Chrome/[\.0-9]*')
&& $this->matchUserAgent('Chrome/[.0-9]*')
) {
if ($this->matchUserAgent('(?:Mobile|eliboM)')) {
$this->device = AbstractDeviceParser::DEVICE_TYPE_SMARTPHONE;
Expand Down
2 changes: 1 addition & 1 deletion Parser/Client/Browser/Engine/Version.php
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ public function parse(): ?array
}

if ('Gecko' === $this->engine || 'Clecko' === $this->engine) {
$pattern = '~[ ](?:rv[: ]([0-9\.]+)).*(?:g|cl)ecko/[0-9]{8,10}~i';
$pattern = '~[ ](?:rv[: ]([0-9.]+)).*(?:g|cl)ecko/[0-9]{8,10}~i';

if (\preg_match($pattern, $this->userAgent, $matches)) {
return ['version' => \array_pop($matches)];
Expand Down
2 changes: 1 addition & 1 deletion Parser/Device/ShellTv.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ class ShellTv extends AbstractDeviceParser
*/
public function isShellTv(): bool
{
$regex = '[a-z]+[ _]Shell[ _]\w{6}|tclwebkit(\d+[\.\d]*)';
$regex = '[a-z]+[ _]Shell[ _]\w{6}|tclwebkit(\d+[.\d]*)';
$match = $this->matchUserAgent($regex);

return null !== $match;
Expand Down
2 changes: 1 addition & 1 deletion regexes/bots.yml
Original file line number Diff line number Diff line change
Expand Up @@ -981,7 +981,7 @@
name: ''
url: 'https://ip-guide.com'

- regex: 'k6/[0-9\.]+'
- regex: 'k6/[0-9.]+'
name: 'K6'
url: 'https://k6.io/'

Expand Down
Loading

0 comments on commit bedd142

Please sign in to comment.