Treat 'Mediapartners-Google' as a robot

This commit is contained in:
Kijin Sung 2019-12-23 13:50:15 +09:00
parent 273fe651bf
commit e3da3ba794
2 changed files with 9 additions and 3 deletions

View file

@ -146,7 +146,7 @@ class UA
} }
// Look for common search engine names and the 'bot' keyword. // Look for common search engine names and the 'bot' keyword.
if (preg_match('/bot|spider|crawler|archiver|wget|curl|php|slurp|wordpress|facebook|teoma|yeti|daum|[(<+]https?:|@/i', $ua)) if (preg_match('/bot|spider|crawler|archiver|wget|curl|php|slurp|wordpress|facebook|teoma|yeti|daum|mediapartners-google|[(<+]https?:|@/i', $ua))
{ {
return self::$_robot_cache[$ua] = true; return self::$_robot_cache[$ua] = true;
} }
@ -308,10 +308,10 @@ class UA
$result->version = $matches[1]; $result->version = $matches[1];
return $result; return $result;
} }
if (preg_match('#^([a-zA-Z0-9_-]+)/([0-9]+\\.[0-9]+)#', $ua, $matches)) if (preg_match('#^([a-zA-Z0-9_-]+)(?:/([0-9]+\\.[0-9]+))?#', $ua, $matches))
{ {
$result->browser = ucfirst($matches[1]); $result->browser = ucfirst($matches[1]);
$result->version = $matches[2]; $result->version = $matches[2] ?: null;
return $result; return $result;
} }

View file

@ -240,6 +240,12 @@ class UATest extends \Codeception\TestCase\Test
$this->assertEquals('1.0', $browser->version); $this->assertEquals('1.0', $browser->version);
$this->assertTrue($browser->is_robot); $this->assertTrue($browser->is_robot);
// Mediapartners-Google
$browser = Rhymix\Framework\UA::getBrowserInfo('Mediapartners-Google');
$this->assertEquals('Mediapartners-Google', $browser->browser);
$this->assertEquals(null, $browser->version);
$this->assertTrue($browser->is_robot);
// Bingbot // Bingbot
$browser = Rhymix\Framework\UA::getBrowserInfo('Mozilla/5.0 (compatible; bingbot/2.0; +http://www.bing.com/bingbot.htm)'); $browser = Rhymix\Framework\UA::getBrowserInfo('Mozilla/5.0 (compatible; bingbot/2.0; +http://www.bing.com/bingbot.htm)');
$this->assertEquals('Bingbot', $browser->browser); $this->assertEquals('Bingbot', $browser->browser);