Merge branch 'CRM-15365' into 4.5
authorColeman Watts <coleman@civicrm.org>
Fri, 26 Sep 2014 20:45:30 +0000 (16:45 -0400)
committerColeman Watts <coleman@civicrm.org>
Fri, 26 Sep 2014 20:45:30 +0000 (16:45 -0400)
CRM/Admin/Form/Setting/UpdateConfigBackend.php
CRM/Utils/File.php

index 7fadf6264b095fadc229556283872ad5433ba497..7ea6bde55fe357f84efacf9c986ca096ad2e8684 100644 (file)
@@ -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,"/");
       }
     }
index d8a41f090412e7ddfdbfec8649aae96aea85a2c9..82f18f5f45ce244b5a6b80143ddcdf02462ff426 100644 (file)
@@ -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;
   }
 
   /**