From 5c8cb77fc8ab2c40d1197a5f034eec268915431d Mon Sep 17 00:00:00 2001 From: Coleman Watts Date: Fri, 26 Sep 2014 14:09:48 -0400 Subject: [PATCH] Directory path code cleanup --- .../Form/Setting/UpdateConfigBackend.php | 8 +++---- CRM/Utils/File.php | 21 ++++++++++--------- 2 files changed, 14 insertions(+), 15 deletions(-) diff --git a/CRM/Admin/Form/Setting/UpdateConfigBackend.php b/CRM/Admin/Form/Setting/UpdateConfigBackend.php index 7fadf6264b..7ea6bde55f 100644 --- a/CRM/Admin/Form/Setting/UpdateConfigBackend.php +++ b/CRM/Admin/Form/Setting/UpdateConfigBackend.php @@ -134,16 +134,14 @@ class CRM_Admin_Form_Setting_UpdateConfigBackend extends CRM_Admin_Form_Setting //CRM-5679 foreach ($params as $name => & $val) { - if ($val && in_array($name, array( - 'newBaseDir', 'newSiteName'))) { + if ($val && in_array($name, array('newBaseDir', 'newSiteName'))) { $val = CRM_Utils_File::addTrailingSlash($val); } } //CRM-15365 - Fix BaseURL to avoid wrong trailing slash on Windows installs - foreach ($params as $name => & $val) { - if ($val && in_array($name, array( - 'newBaseURL'))) { + foreach ($params as $name => & $val) { + if ($val && in_array($name, array('newBaseURL'))) { $val = CRM_Utils_File::addTrailingSlash($val,"/"); } } diff --git a/CRM/Utils/File.php b/CRM/Utils/File.php index d8a41f0904..82f18f5f45 100644 --- a/CRM/Utils/File.php +++ b/CRM/Utils/File.php @@ -244,24 +244,25 @@ class CRM_Utils_File { } /** - * Appends trailing slashed to paths + * Appends a slash to the end of a string if it doesn't already end with one * - * @param $name - * @param null $separator + * @param string $path + * @param string $slash * * @return string * @access public * @static */ - static function addTrailingSlash($name, $separator = NULL) { - if (!$separator) { - $separator = DIRECTORY_SEPARATOR; + static function addTrailingSlash($path, $slash = NULL) { + if (!$slash) { + // FIXME: Defaulting to backslash on windows systems can produce unexpected results, esp for URL strings which should always use forward-slashes. + // I think this fn should default to forward-slash instead. + $slash = DIRECTORY_SEPARATOR; } - - if (!in_array(substr($name, -1, 1), array('/', '\\'))) { - $name .= $separator; + if (!in_array(substr($path, -1, 1), array('/', '\\'))) { + $path .= $slash; } - return $name; + return $path; } /** -- 2.25.1