From a102302ccc6c85ee06507c7755211ffeabd3b7a2 Mon Sep 17 00:00:00 2001 From: mpetty Date: Thu, 17 Jan 2019 09:58:38 -0500 Subject: [PATCH 1/4] fixed a bug with browser version detection when rules are an array --- src/Agent.php | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/Agent.php b/src/Agent.php index 0d13031..48d82b7 100644 --- a/src/Agent.php +++ b/src/Agent.php @@ -347,6 +347,8 @@ protected static function mergeRules(...$all) foreach ($all as $rules) { foreach ($rules as $key => $value) { + if (is_array($value)) $value = implode('|', $value); + if (empty($merged[$key])) { $merged[$key] = $value; } elseif (is_array($merged[$key])) { From deeb4319090fcf773ec6b6c70ada9cf41dda25c4 Mon Sep 17 00:00:00 2001 From: mpetty Date: Thu, 17 Jan 2019 10:09:16 -0500 Subject: [PATCH 2/4] updated code syntax for version fix bc of syntax check error --- src/Agent.php | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/Agent.php b/src/Agent.php index 48d82b7..7fd4d03 100644 --- a/src/Agent.php +++ b/src/Agent.php @@ -347,7 +347,9 @@ protected static function mergeRules(...$all) foreach ($all as $rules) { foreach ($rules as $key => $value) { - if (is_array($value)) $value = implode('|', $value); + if (is_array($value)) { + $value = implode('|', $value); + } if (empty($merged[$key])) { $merged[$key] = $value; From 5f2717b89a407dc84a1ea9bd82298f22c1ff904f Mon Sep 17 00:00:00 2001 From: mpetty Date: Thu, 17 Jan 2019 11:37:43 -0500 Subject: [PATCH 3/4] moved property match check to version method --- src/Agent.php | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/Agent.php b/src/Agent.php index 7fd4d03..a1549f0 100644 --- a/src/Agent.php +++ b/src/Agent.php @@ -320,6 +320,10 @@ public function version($propertyName, $type = self::VERSION_TYPE_STRING) $properties[$propertyName] = (array) $properties[$propertyName]; foreach ($properties[$propertyName] as $propertyMatchString) { + if (is_array($propertyMatchString)) { + $propertyMatchString = implode("|", $propertyMatchString); + } + $propertyPattern = str_replace('[VER]', self::VER, $propertyMatchString); // Identify and extract the version. @@ -347,10 +351,6 @@ protected static function mergeRules(...$all) foreach ($all as $rules) { foreach ($rules as $key => $value) { - if (is_array($value)) { - $value = implode('|', $value); - } - if (empty($merged[$key])) { $merged[$key] = $value; } elseif (is_array($merged[$key])) { From ac5bfefc63b5663f56923bdd2c56bbb82db11d5f Mon Sep 17 00:00:00 2001 From: mpetty Date: Thu, 17 Jan 2019 12:44:27 -0500 Subject: [PATCH 4/4] added test to check invalid user agent string against browsers --- tests/AgentTest.php | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/tests/AgentTest.php b/tests/AgentTest.php index f9a8935..a816ed5 100644 --- a/tests/AgentTest.php +++ b/tests/AgentTest.php @@ -222,6 +222,11 @@ public function testVersions() $platform = $agent->platform(); $this->assertEquals($version, $agent->version($platform), $ua); } + + foreach ($this->browsers as $ua => $browser) { + $agent->setUserAgent('FAKE'); + $this->assertFalse($agent->version($browser)); + } } public function testIsMethods()