diff --git a/README.md b/README.md index 7cbe264..33fa4ab 100644 --- a/README.md +++ b/README.md @@ -86,6 +86,7 @@ array( - BlackBerry - Playbook - Tizen + - Sailfish OS - Console - Oculus - Nintendo 3DS @@ -116,6 +117,8 @@ array( - TizenBrowser - OculusBrowser - SamsungBrowser +- Sailfish Browser +- Miui Browser - UC Browser - Lynx - Wget diff --git a/src/UserAgentParser.php b/src/UserAgentParser.php index 3617053..bf2649b 100644 --- a/src/UserAgentParser.php +++ b/src/UserAgentParser.php @@ -34,11 +34,11 @@ function parse_user_agent( $u_agent = null ) { } if( preg_match('/\((.*?)\)/m', $u_agent, $parent_matches) ) { - preg_match_all('/(?PBB\d+;|Android|Adr|Symbian|CrOS|Tizen|iPhone|iPad|iPod|Linux|(Open|Net|Free)BSD|Macintosh|Windows(\ Phone)?|Silk|linux-gnu|BlackBerry|PlayBook|X11|(New\ )?Nintendo\ (WiiU?|3?DS|Switch)|Xbox(\ One)?) + preg_match_all('/(?PBB\d+;|Android|Adr|Symbian|Sailfish|CrOS|Tizen|iPhone|iPad|iPod|Linux|(Open|Net|Free)BSD|Macintosh|Windows(\ Phone)?|Silk|linux-gnu|BlackBerry|PlayBook|X11|(New\ )?Nintendo\ (WiiU?|3?DS|Switch)|Xbox(\ One)?) (?:\ [^;]*)? (?:;|$)/imx', $parent_matches[1], $result); - $priority = array( 'Xbox One', 'Xbox', 'Windows Phone', 'Tizen', 'Android', 'FreeBSD', 'NetBSD', 'OpenBSD', 'CrOS', 'X11' ); + $priority = array( 'Xbox One', 'Xbox', 'Windows Phone', 'Tizen', 'Android', 'FreeBSD', 'NetBSD', 'OpenBSD', 'CrOS', 'X11', 'Sailfish' ); $result['platform'] = array_unique($result['platform']); if( count($result['platform']) > 1 ) { @@ -61,7 +61,8 @@ function parse_user_agent( $u_agent = null ) { } preg_match_all('%(?PCamino|Kindle(\ Fire)?|Firefox|Iceweasel|IceCat|Safari|MSIE|Trident|AppleWebKit| - TizenBrowser|(?:Headless)?Chrome|YaBrowser|Vivaldi|IEMobile|Opera|OPR|Silk|Midori|Edge|Edg|CriOS|UCBrowser|Puffin|OculusBrowser|SamsungBrowser| + TizenBrowser|(?:Headless)?Chrome|YaBrowser|Vivaldi|IEMobile|Opera|OPR|Silk|Midori|Edge|Edg|CriOS|UCBrowser|Puffin| + OculusBrowser|SamsungBrowser|SailfishBrowser|XiaoMi/MiuiBrowser| Baiduspider|Applebot|Googlebot|YandexBot|bingbot|Lynx|Version|Wget|curl| Valve\ Steam\ Tenfoot| NintendoBrowser|PLAYSTATION\ (\d|Vita)+) @@ -116,7 +117,7 @@ function parse_user_agent( $u_agent = null ) { $key = 0; $val = ''; - if( $findT(array( 'OPR' => 'Opera', 'UCBrowser' => 'UC Browser', 'YaBrowser' => 'Yandex', 'Iceweasel' => 'Firefox', 'Icecat' => 'Firefox', 'CriOS' => 'Chrome', 'Edg' => 'Edge' ), $key, $browser) ) { + if( $findT(array( 'OPR' => 'Opera', 'UCBrowser' => 'UC Browser', 'YaBrowser' => 'Yandex', 'Iceweasel' => 'Firefox', 'Icecat' => 'Firefox', 'CriOS' => 'Chrome', 'Edg' => 'Edge', 'XiaoMi/MiuiBrowser' => 'MiuiBrowser' ), $key, $browser) ) { $version = $result['version'][$key]; }elseif( $find('Playstation Vita', $key, $platform) ) { $platform = 'PlayStation Vita'; @@ -149,7 +150,7 @@ function parse_user_agent( $u_agent = null ) { } } } - } elseif( $find(array( 'Applebot', 'IEMobile', 'Edge', 'Midori', 'Vivaldi', 'OculusBrowser', 'SamsungBrowser', 'Valve Steam Tenfoot', 'Chrome', 'HeadlessChrome' ), $key, $browser) ) { + } elseif( $find(array( 'Applebot', 'IEMobile', 'Edge', 'Midori', 'Vivaldi', 'OculusBrowser', 'SamsungBrowser', 'Valve Steam Tenfoot', 'Chrome', 'HeadlessChrome', 'SailfishBrowser' ), $key, $browser) ) { $version = $result['version'][$key]; } elseif( $rv_result && $find('Trident') ) { $browser = 'MSIE'; diff --git a/tests/UserAgentParserTest.php b/tests/UserAgentParserTest.php index 6d02d46..4082ef2 100644 --- a/tests/UserAgentParserTest.php +++ b/tests/UserAgentParserTest.php @@ -47,6 +47,7 @@ public function test_no_user_agent_exception() { try { parse_user_agent(); } catch(\InvalidArgumentException $ex) { + $this->assertTrue(true); // quiet warning return; } diff --git a/tests/user_agents.json b/tests/user_agents.json index 1463bec..723f8c6 100644 --- a/tests/user_agents.json +++ b/tests/user_agents.json @@ -519,6 +519,21 @@ "browser": "Chrome", "version": "18.0.1025.308" }, + "Mozilla\/5.0 (Linux; U; Android 8.1.0; en-gb; Redmi Note 5 Build\/OPM1.171019.011)\nAppleWebKit\/537.36 (KHTML, like Gecko) Version\/4.0 Chrome\/61.0.3163.128 Mobile\nSafari\/537.36 XiaoMi\/MiuiBrowser\/10.1.2": { + "platform": "Android", + "browser": "MiuiBrowser", + "version": "10.1.2" + }, + "Mozilla\/5.0 (Linux; U; Android 10; bg-bg; Mi Note 10 Build\/QKQ1.190825.002) AppleWebKit\/537.36 (KHTML, like Gecko) Version\/4.0 Chrome\/71.0.3578.141 Mobile Safari\/537.36 XiaoMi\/MiuiBrowser\/12.6.2-gn": { + "platform": "Android", + "browser": "MiuiBrowser", + "version": "12.6.2" + }, + "Mozilla\/5.0 (Linux; U; Android 10; ru-ru; Redmi Note 7 Build\/QKQ1.190910.002) AppleWebKit\/537.36 (KHTML, like Gecko) Version\/4.0 Chrome\/71.0.3578.141 Mobile Safari\/537.36 XiaoMi\/MiuiBrowser\/12.6.6-gn": { + "platform": "Android", + "browser": "MiuiBrowser", + "version": "12.6.6" + }, "Mozilla\/5.0 (Linux; Android 7.1.2; Pacific Build\/N2G48H) AppleWebKit\/537.36 (KHTML, like Gecko) OculusBrowser\/5.5.10.137831012 SamsungBrowser\/4.0 Chrome\/66.0.3359.203 Mobile VR Safari\/537.36": { "platform": "Android", "browser": "OculusBrowser", @@ -914,6 +929,26 @@ "browser": "Browser", "version": "1.69" }, + "Mozilla\/5.0 (Linux; U; Sailfish 3.0; Mobile; rv:38.0) Gecko\/38.0 Firefox\/38.0 SailfishBrowser\/1.0": { + "platform": "Sailfish", + "browser": "SailfishBrowser", + "version": "1.0" + }, + "Mozilla\/5.0 (Linux; U; Sailfish 3.0; Tablet; rv:38.0) Gecko\/38.0 Firefox\/38.0 SailfishBrowser\/1.0": { + "platform": "Sailfish", + "browser": "SailfishBrowser", + "version": "1.0" + }, + "Mozilla\/5.0 (Maemo; Linux; U; Jolla; Sailfish; Mobile; rv:31.0) Gecko\/31.0 Firefox\/31.0 SailfishBrowser\/1.0": { + "platform": "Sailfish", + "browser": "SailfishBrowser", + "version": "1.0" + }, + "Mozilla\/5.0 (Maemo; Linux; U; Jolla; Sailfish; Tablet; rv:31.0) Gecko\/31.0 Firefox\/31.0 SailfishBrowser\/1.0": { + "platform": "Sailfish", + "browser": "SailfishBrowser", + "version": "1.0" + }, "UCWEB\/2.0 (Symbian; U; S60 V5; id; NokiaN8-00) U2\/1.0.0 UCBrowser\/9.2.0.336 U2\/1.0.0 Mobile": { "platform": "Symbian", "browser": "UC Browser",