Fix undefined HTTP_USER_AGENT

This commit is contained in:
Thomas Müller 2015-11-18 15:27:17 +01:00 committed by Lukas Reschke
parent e8661a6b56
commit 358858c9e3
2 changed files with 28 additions and 8 deletions

View File

@ -674,6 +674,9 @@ class Request implements \ArrayAccess, \Countable, IRequest {
* @return bool true if at least one of the given agent matches, false otherwise
*/
public function isUserAgent(array $agent) {
if (!isset($this->server['HTTP_USER_AGENT'])) {
return false;
}
foreach ($agent as $regex) {
if (preg_match($regex, $this->server['HTTP_USER_AGENT'])) {
return true;

View File

@ -693,19 +693,36 @@ class RequestTest extends \Test\TestCase {
*/
public function testUserAgent($testAgent, $userAgent, $matches) {
$request = new Request(
[
'server' => [
'HTTP_USER_AGENT' => $testAgent,
]
],
$this->secureRandom,
$this->config,
$this->stream
[
'server' => [
'HTTP_USER_AGENT' => $testAgent,
]
],
$this->secureRandom,
$this->config,
$this->stream
);
$this->assertSame($matches, $request->isUserAgent($userAgent));
}
/**
* @dataProvider userAgentProvider
* @param string $testAgent
* @param array $userAgent
* @param bool $matches
*/
public function testUndefinedUserAgent($testAgent, $userAgent, $matches) {
$request = new Request(
[],
$this->secureRandom,
$this->config,
$this->stream
);
$this->assertFalse($request->isUserAgent($userAgent));
}
/**
* @return array
*/