Skip to content
Open
Show file tree
Hide file tree
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
11 changes: 6 additions & 5 deletions lib/phpUserAgentStringParser.php
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ public function parse($userAgentString = null)

/**
* Detect quickly informations from the user agent string
*
*
* @param string $userAgentString user agent string
* @return array user agent informations array
*/
Expand Down Expand Up @@ -83,7 +83,7 @@ protected function doParse($userAgentString)

// Find operating system
$pattern = '#'.join('|', $this->getKnownOperatingSystems()).'#';

if (preg_match($pattern, $userAgent['string'], $match))
{
if (isset($match[0]))
Expand All @@ -94,7 +94,7 @@ protected function doParse($userAgentString)

// Find engine
$pattern = '#'.join('|', $this->getKnownEngines()).'#';

if (preg_match($pattern, $userAgent['string'], $match))
{
if (isset($match[0]))
Expand Down Expand Up @@ -148,7 +148,7 @@ public function getFilters()

/**
* Add a filter to be called when parsing a user agent
*
*
* @param string $filter name of the filter method
*/
public function addFilter($filter)
Expand Down Expand Up @@ -209,7 +209,8 @@ protected function getKnownOperatingSystems()
'linux',
'freebsd',
'unix',
'iphone'
'iphone',
'ipad'
);
}

Expand Down
39 changes: 21 additions & 18 deletions test/StringParserTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -80,29 +80,32 @@
'Mozilla/5.0 (iPhone; U; CPU iPhone OS 3_1_2 like Mac OS X; de-de) AppleWebKit/528.18 (KHTML, like Gecko) Mobile/7D11'
=> array('applewebkit', '528.18', 'iphone', 'webkit'),

// Motorola Xoom
'Mozilla/5.0 (Linux; U; Android 3.0; en-us; Xoom Build/HRI39) AppleWebKit/534.13 (KHTML, like Gecko) Version/4.0 Safari/534.13' =>
array('android', '3.0', 'android', 'webkit'),
// Motorola Xoom
'Mozilla/5.0 (Linux; U; Android 3.0; en-us; Xoom Build/HRI39) AppleWebKit/534.13 (KHTML, like Gecko) Version/4.0 Safari/534.13'
=> array('android', '3.0', 'android', 'webkit'),

// Samsung Galaxy Tab
'Mozilla/5.0 (Linux U Android 2.2 es-es GT-P1000 Build/FROYO) AppleWebKit/533.1 (KHTML, like Gecko) Version/4.0 Mobile Safari/533.1' =>
array('android', '2.2', 'android', 'webkit'),
// Samsung Galaxy Tab
'Mozilla/5.0 (Linux U Android 2.2 es-es GT-P1000 Build/FROYO) AppleWebKit/533.1 (KHTML, like Gecko) Version/4.0 Mobile Safari/533.1'
=> array('android', '2.2', 'android', 'webkit'),

// Google Nexus
'Mozilla/5.0 (Linux; U; Android 2.2; en-us; Nexus One Build/FRF91) AppleWebKit/533.1 (KHTML, like Gecko) Version/4.0 Mobile Safari/533.1' =>
array('android', '2.2', 'android', 'webkit'),
// Google Nexus
'Mozilla/5.0 (Linux; U; Android 2.2; en-us; Nexus One Build/FRF91) AppleWebKit/533.1 (KHTML, like Gecko) Version/4.0 Mobile Safari/533.1'
=> array('android', '2.2', 'android', 'webkit'),

// HTC Desire
// HTC Desire
'Mozilla/5.0 (Linux; U; Android 2.1-update1; de-de; HTC Desire 1.19.161.5 Build/ERE27) AppleWebKit/530.17 (KHTML, like Gecko) Version/4.0 Mobile Safari/530.17'
=> array('android', '2.1', 'android', 'webkit'),

'Mozilla/5.0 (Linux; U; Android 2.1-update1; de-de; HTC Desire 1.19.161.5 Build/ERE27) AppleWebKit/530.17 (KHTML, like Gecko) Version/4.0 Mobile Safari/530.17' =>
array('android', '2.1', 'android', 'webkit'),
'Mozilla/5.0 (Linux; U; Android 2.3.6; ru-ru; GT-B5512 Build/GINGERBREAD) AppleWebKit/533.1 (KHTML, like Gecko) Version/4.0 Mobile Safari/533.1'
=> array('android', '2.3.6', 'android', 'webkit'),

'Mozilla/5.0 (Linux; U; Android 2.3.6; ru-ru; GT-B5512 Build/GINGERBREAD) AppleWebKit/533.1 (KHTML, like Gecko) Version/4.0 Mobile Safari/533.1' =>
array('android', '2.3.6', 'android', 'webkit'),
// Nexus 7
'Mozilla/5.0 (Linux; Android 4.1.1; Nexus 7 Build/JRO03D) AppleWebKit/535.19 (KHTML, like Gecko) Chrome/18.0.1025.166 Safari/535.19'
=> array('android', '4.1.1', 'android', 'webkit'),

// Nexus 7
'Mozilla/5.0 (Linux; Android 4.1.1; Nexus 7 Build/JRO03D) AppleWebKit/535.19 (KHTML, like Gecko) Chrome/18.0.1025.166 Safari/535.19' =>
array('android', '4.1.1', 'android', 'webkit'),
// Ipad
'Mozilla/5.0 (iPad; CPU OS 6_1_3 like Mac OS X) AppleWebKit/536.26 (KHTML, like Gecko) Version/6.0 Mobile/10B329 Safari/8536.25'
=> array('safari', '6.0', 'ipad', 'webkit'),
);

$t = new lime_test(count($tests));
Expand All @@ -120,6 +123,6 @@
);

$result = $parser->parse($userAgentString);

$t->is_deeply($result, $expected, $userAgentString.' -> '.implode(', ', $result));
}