Skip to content

Commit

Permalink
Simplify empty Android platform chjeck
Browse files Browse the repository at this point in the history
  • Loading branch information
donatj committed Aug 8, 2022
1 parent af736e4 commit 801e198
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 11 deletions.
8 changes: 2 additions & 6 deletions src/UserAgentParser.php
Original file line number Diff line number Diff line change
Expand Up @@ -90,11 +90,7 @@ function parse_user_agent( $u_agent = null ) {
} elseif( $platform == 'Adr' ) {
$platform = 'Android';
} elseif( $platform === null ) {
if(preg_match_all(<<<'REGEX'
%(?P<platform>Android)
(?:[:/ ](?P<version>[0-9A-Z.]+)|/[A-Z]*)%ix
REGEX
, $u_agent, $result)) {
if(preg_match_all('%(?P<platform>Android)[:/ ]%ix', $u_agent, $result)) {
$platform = $result[PLATFORM][0];
}
}
Expand Down Expand Up @@ -199,7 +195,7 @@ function parse_user_agent( $u_agent = null ) {
} elseif( $browser == 'AppleWebKit' ) {
if( $platform == 'Android' ) {
$browser = 'Android Browser';
} elseif( $platform !== null && strpos($platform, 'BB') === 0 ) {
} elseif( strpos((string)$platform, 'BB') === 0 ) {
$browser = 'BlackBerry Browser';
$platform = 'BlackBerry';
} elseif( $platform == 'BlackBerry' || $platform == 'PlayBook' ) {
Expand Down
10 changes: 5 additions & 5 deletions tests/user_agents.dist.json
Original file line number Diff line number Diff line change
Expand Up @@ -619,6 +619,11 @@
"browser": "Android Browser",
"version": "4.0"
},
"Lenovo-A880\/S100 Linux\/3.4.5 Android\/4.2 Release\/08.07.2013 Browser\/AppleWebKit 534.30 Profile\/ Configuration;": {
"platform": "Android",
"browser": "Android Browser",
"version": "534.30"
},
"Mozilla\/5.0 (Linux; Android 4.2.2; de-at; SAMSUNG GT-I9195\/I9195XXUAMF6 Build\/JDQ39) AppleWebKit\/535.19 (KHTML, like Gecko) Version\/1.0 Chrome\/18.0.1025.308 Mobile Safari\/535.19": {
"platform": "Android",
"browser": "Chrome",
Expand Down Expand Up @@ -1368,10 +1373,5 @@
"platform": null,
"browser": "YandexBot",
"version": "3.0"
},
"Lenovo-A880/S100 Linux/3.4.5 Android/4.2 Release/08.07.2013 Browser/AppleWebKit 534.30 Profile/ Configuration;": {
"platform": "Android",
"browser": "Android Browser",
"version": "534.30"
}
}

0 comments on commit 801e198

Please sign in to comment.