From 218e898c00d11e009b5276e74f3b68272475ec9c Mon Sep 17 00:00:00 2001
From: Thomas Steur <thomas.steur@googlemail.com>
Date: Wed, 9 Apr 2014 07:05:06 +0200
Subject: [PATCH] refs #4967 handle whitespace

---
 core/Plugin/Dependency.php            |  5 ++++-
 tests/PHPUnit/Core/DependencyTest.php | 17 +++++++++++++++++
 2 files changed, 21 insertions(+), 1 deletion(-)

diff --git a/core/Plugin/Dependency.php b/core/Plugin/Dependency.php
index 733c1be2c0..0448f8a721 100644
--- a/core/Plugin/Dependency.php
+++ b/core/Plugin/Dependency.php
@@ -49,6 +49,7 @@ class Dependency
 
     public function getMissingVersions($currentVersion, $requiredVersion)
     {
+        $currentVersion   = trim($currentVersion);
         $requiredVersions = explode(',' , (string) $requiredVersion);
 
         $missingVersions = array();
@@ -56,11 +57,13 @@ class Dependency
         foreach ($requiredVersions as $required) {
 
             $comparison = '>=';
+            $required   = trim($required);
 
             if (preg_match('{^(<>|!=|>=?|<=?|==?)\s*(.*)}', $required, $matches)) {
                 $required   = $matches[2];
-                $comparison = $matches[1];
+                $comparison = trim($matches[1]);
             }
+
             if (false === version_compare($currentVersion, $required, $comparison)) {
                 $missingVersions[] = $comparison . $required;
             }
diff --git a/tests/PHPUnit/Core/DependencyTest.php b/tests/PHPUnit/Core/DependencyTest.php
index 4444d33424..3bd1bd5793 100644
--- a/tests/PHPUnit/Core/DependencyTest.php
+++ b/tests/PHPUnit/Core/DependencyTest.php
@@ -149,6 +149,14 @@ class DependencyTest extends PHPUnit_Framework_TestCase
         $this->assertMissingVersion('5.5', '', array());
     }
 
+    public function test_getMissingVersion_shouldIgnoreAnyWhitespace()
+    {
+        $this->assertMissingVersion('5.5 ', '5.5', array());
+        $this->assertMissingVersion(' 5.5 ', '5.5', array());
+        $this->assertMissingVersion('5.5', ' 5.5', array());
+        $this->assertMissingVersion('5.5', ' 5.5 ', array());
+    }
+
     public function test_getMissingVersion_NoComparisonDefined_ShouldUseGreatherThanOrEqualByDefault()
     {
         $this->assertMissingVersion('5.4', '5.2', array());
@@ -214,6 +222,15 @@ class DependencyTest extends PHPUnit_Framework_TestCase
         $this->assertMissingVersion('5.4', '<2.0,>=9.0', array('<2.0', '>=9.0'));
     }
 
+    public function test_getMissingVersion_AND_Condition_shouldIgnoreAnyWhitespace()
+    {
+        $this->assertMissingVersion('5.2', '5.5 , 5.4,   5.3', array('>=5.5', '>=5.4', '>=5.3'));
+        $this->assertMissingVersion('5.5', '5.5 , 5.4,   5.3', array());
+        $this->assertMissingVersion(' 5.2 ', '5.5 , 5.4,   5.3', array('>=5.5', '>=5.4', '>=5.3'));
+        $this->assertMissingVersion(' 5.2 ', '>5.5 , <5.4,   ==5.3', array('>5.5', '==5.3'));
+        $this->assertMissingVersion(' 5.2 ', '>5.5 , !=5.4,   ==5.3', array('>5.5', '==5.3'));
+    }
+
     public function test_getMissingVersion()
     {
         $this->assertMissingVersion('5.2', '<5.2,>9.0', array('<5.2', '>9.0'));
-- 
GitLab