From 517c9f9a8dba8e83eaa37a7660f434102e967a77 Mon Sep 17 00:00:00 2001
From: Aleksander Machniak <alec@alec.pl>
Date: Fri, 07 Feb 2014 08:43:51 -0500
Subject: [PATCH] Fix directories check in Installer on Windows (#1489576) Added rcube_utils::is_absolute_path() method

---
 CHANGELOG                              |    1 +
 installer/test.php                     |    2 +-
 program/lib/Roundcube/rcube_config.php |   14 +++-----------
 tests/Framework/Utils.php              |   28 +++++++++++++++++++++++++++-
 program/lib/Roundcube/rcube_utils.php  |   12 ++++++++++++
 5 files changed, 44 insertions(+), 13 deletions(-)

diff --git a/CHANGELOG b/CHANGELOG
index 020026d..80c70a7 100644
--- a/CHANGELOG
+++ b/CHANGELOG
@@ -1,6 +1,7 @@
 CHANGELOG Roundcube Webmail
 ===========================
 
+- Fix directories check in Installer on Windows (#1489576)
 - Fix issue when default_addressbook option is set to integer value (#1489407)
 - Fix Opera > 15 detection (#1489562)
 
diff --git a/installer/test.php b/installer/test.php
index f834308..5d28d5f 100644
--- a/installer/test.php
+++ b/installer/test.php
@@ -91,7 +91,7 @@
     $dirs[] = $RCI->config['log_dir'] ? $RCI->config['log_dir'] : 'logs';
 
 foreach ($dirs as $dir) {
-    $dirpath = $dir[0] == '/' ? $dir : INSTALL_PATH . $dir;
+    $dirpath = rcube_utils::is_absolute_path($dir) ? $dir : INSTALL_PATH . $dir;
     if (is_writable(realpath($dirpath))) {
         $RCI->pass($dir);
         $pass = true;
diff --git a/program/lib/Roundcube/rcube_config.php b/program/lib/Roundcube/rcube_config.php
index 0352e47..afe13e8 100644
--- a/program/lib/Roundcube/rcube_config.php
+++ b/program/lib/Roundcube/rcube_config.php
@@ -63,7 +63,7 @@
             $this->paths = explode(PATH_SEPARATOR, $paths);
             // make all paths absolute
             foreach ($this->paths as $i => $path) {
-                if (!$this->_is_absolute($path)) {
+                if (!rcube_utils::is_absolute_path($path)) {
                     if ($realpath = realpath(RCUBE_INSTALL_PATH . $path)) {
                         $this->paths[$i] = unslashify($realpath) . '/';
                     }
@@ -243,8 +243,8 @@
      */
     public function resolve_paths($file, $use_env = true)
     {
-        $files = array();
-        $abs_path = $this->_is_absolute($file);
+        $files    = array();
+        $abs_path = rcube_utils::is_absolute_path($file);
 
         foreach ($this->paths as $basepath) {
             $realpath = $abs_path ? $file : realpath($basepath . '/' . $file);
@@ -267,14 +267,6 @@
         }
 
         return $files;
-    }
-
-    /**
-     * Determine whether the given file path is absolute or relative
-     */
-    private function _is_absolute($path)
-    {
-        return $path[0] == DIRECTORY_SEPARATOR || preg_match('!^[a-z]:[\\\\/]!i', $path);
     }
 
     /**
diff --git a/program/lib/Roundcube/rcube_utils.php b/program/lib/Roundcube/rcube_utils.php
index c48cd80..46d53ac 100644
--- a/program/lib/Roundcube/rcube_utils.php
+++ b/program/lib/Roundcube/rcube_utils.php
@@ -1045,4 +1045,16 @@
         return !in_array($str, array('false', '0', 'no', 'off', 'nein', ''), true);
     }
 
+    /**
+     * OS-dependent absolute path detection
+     */
+    public static function is_absolute_path($path)
+    {
+        if (strtoupper(substr(PHP_OS, 0, 3)) == 'WIN') {
+            return (bool) preg_match('!^[a-z]:[\\\\/]!i', $path);
+        }
+        else {
+            return $path[0] == DIRECTORY_SEPARATOR;
+        }
+    }
 }
diff --git a/tests/Framework/Utils.php b/tests/Framework/Utils.php
index 1f1e57b..082aaea 100644
--- a/tests/Framework/Utils.php
+++ b/tests/Framework/Utils.php
@@ -320,7 +320,7 @@
     }
 
     /**
-     * rcube:utils::normalize _string()
+     * rcube:utils::normalize_string()
      */
     function test_normalize_string()
     {
@@ -334,4 +334,30 @@
             $this->assertSame($output, $result);
         }
     }
+
+    /**
+     * rcube:utils::is_absolute_path()
+     */
+    function test_is_absolute_path()
+    {
+        if (strtoupper(substr(PHP_OS, 0, 3)) == 'WIN') {
+            $test = array(
+                '' => false,
+                "C:\\" => true,
+                'some/path' => false,
+            );
+        }
+        else {
+            $test = array(
+                '' => false,
+                '/path' => true,
+                'some/path' => false,
+            );
+        }
+
+        foreach ($test as $input => $output) {
+            $result = rcube_utils::is_absolute_path($input);
+            $this->assertSame($output, $result);
+        }
+    }
 }

--
Gitblit v1.9.1