From 9f87b14bf20919f5896ac2ff91805a1669d58c10 Mon Sep 17 00:00:00 2001 From: Tim Otten Date: Mon, 18 May 2015 22:09:24 -0700 Subject: [PATCH] CRM-16499 - Fix relative Angular paths in Windows --- CRM/Core/Resources.php | 2 +- CRM/Utils/File.php | 24 +++++++++++++++++++++++- 2 files changed, 24 insertions(+), 2 deletions(-) diff --git a/CRM/Core/Resources.php b/CRM/Core/Resources.php index a7f2d3561c45..75ca3926f79e 100644 --- a/CRM/Core/Resources.php +++ b/CRM/Core/Resources.php @@ -525,7 +525,7 @@ public function glob($ext, $patterns, $flags = NULL) { $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)); } diff --git a/CRM/Utils/File.php b/CRM/Utils/File.php index 73c9bf50ab5c..a8ca3b77c3c1 100644 --- a/CRM/Utils/File.php +++ b/CRM/Utils/File.php @@ -520,6 +520,24 @@ public static function baseFilePath($templateCompileDir = NULL) { 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 @@ public static function relativeDirectory($directory) { } // 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 @@ public static function absoluteDirectory($directory) { * @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)); }