CRM-16499 - Fix relative Angular paths in Windows
authorTim Otten <totten@civicr.org>
Tue, 19 May 2015 05:09:24 +0000 (22:09 -0700)
committerTim Otten <totten@civicr.org>
Tue, 19 May 2015 05:21:15 +0000 (22:21 -0700)
CRM/Core/Resources.php
CRM/Utils/File.php

index a7f2d3561c4530beea623346601d0156176ef00f..75ca3926f79e04252196a602b89132c7f0d416bf 100644 (file)
@@ -525,7 +525,7 @@ class CRM_Core_Resources {
     $patterns = (array) $patterns;
     $files = array();
     foreach ($patterns as $pattern) {
-      if ($pattern{0} === '/') {
+      if (CRM_Utils_File::isAbsolute($pattern)) {
         // Absolute path.
         $files = array_merge($files, (array) glob($pattern, $flags));
       }
index 73c9bf50ab5cfaa150d218076c03bf6757a34be1..a8ca3b77c3c17fb6955fd9a0bf4374cebd8a6197 100644 (file)
@@ -520,6 +520,24 @@ HTACCESS;
     return $_path;
   }
 
+  /**
+   * Determine if a path is absolute.
+   *
+   * @return bool
+   *   TRUE if absolute. FALSE if relative.
+   */
+  public static function isAbsolute($path) {
+    if (substr($path, 0, 1) === DIRECTORY_SEPARATOR) {
+      return TRUE;
+    }
+    if (strtoupper(substr(PHP_OS, 0, 3)) === 'WIN') {
+      if (preg_match('!^[a-zA-Z]:[/\\\\]!', $path)) {
+        return TRUE;
+      }
+    }
+    return FALSE;
+  }
+
   /**
    * @param $directory
    *
@@ -532,7 +550,7 @@ HTACCESS;
     }
 
     // check if directory is relative, if so return immediately
-    if (substr($directory, 0, 1) != DIRECTORY_SEPARATOR) {
+    if (!self::isAbsolute($directory)) {
       return $directory;
     }
 
@@ -580,6 +598,10 @@ HTACCESS;
    * @return string
    */
   public static function relativize($directory, $basePath) {
+    if (strtoupper(substr(PHP_OS, 0, 3)) === 'WIN') {
+      $directory = strtr($directory, '\\', '/');
+      $basePath = strtr($basePath, '\\', '/');
+    }
     if (substr($directory, 0, strlen($basePath)) == $basePath) {
       return substr($directory, strlen($basePath));
     }