diff --git a/core/includes/file.inc b/core/includes/file.inc index f141cc8..3e7e167 100644 --- a/core/includes/file.inc +++ b/core/includes/file.inc @@ -1516,9 +1516,7 @@ function drupal_mkdir($uri, $mode = NULL, $recursive = FALSE, $context = NULL) { // If recursive, create each missing component of the parent directory // individually and set the mode explicitly to override the umask. if ($recursive) { - // Ensure the path is using DIRECTORY_SEPARATOR. - $uri = str_replace('/', DIRECTORY_SEPARATOR, $uri); - // Determine the components of the path. + $components = explode(DIRECTORY_SEPARATOR, $uri); // If the filepath is absolute the first component will be empty as there // will be nothing before the first slash. @@ -1530,6 +1528,11 @@ function drupal_mkdir($uri, $mode = NULL, $recursive = FALSE, $context = NULL) { else { $recursive_path = ''; } + // Ensure the path is using all forward slashes so it can be exploded. + $uri = str_replace('\\', '/', $uri); + // Determine the components of the path. + + $components = explode('/', $uri); // Don't handle the top-level directory in this loop. array_pop($components); // Create each component if necessary. @@ -1546,7 +1549,7 @@ function drupal_mkdir($uri, $mode = NULL, $recursive = FALSE, $context = NULL) { } } - $recursive_path .= DIRECTORY_SEPARATOR; + $recursive_path .= '/'; } } diff --git a/core/modules/system/lib/Drupal/system/Tests/File/DirectoryTest.php b/core/modules/system/lib/Drupal/system/Tests/File/DirectoryTest.php index d17db20..f856137 100644 --- a/core/modules/system/lib/Drupal/system/Tests/File/DirectoryTest.php +++ b/core/modules/system/lib/Drupal/system/Tests/File/DirectoryTest.php @@ -23,7 +23,7 @@ public static function getInfo() { * Test local directory handling functions. */ function testFileCheckLocalDirectoryHandling() { - $directory = conf_path() . '/files'; + $directory = 'public://'; // Check a new recursively created local directory for correct file system // permissions. @@ -31,18 +31,18 @@ function testFileCheckLocalDirectoryHandling() { $child = $this->randomName(); // Files directory already exists. - $this->assertTrue(is_dir($directory), t('Files directory already exists.'), 'File'); + $this->assertTrue(is_dir($directory), 'Files directory already exists.', 'File'); // Make files directory writable only. $old_mode = fileperms($directory); // Create the directories. $parent_path = $directory . DIRECTORY_SEPARATOR . $parent; $child_path = $parent_path . DIRECTORY_SEPARATOR . $child; - $this->assertTrue(drupal_mkdir($child_path, 0775, TRUE), t('No error reported when creating new local directories.'), 'File'); + $this->assertTrue(drupal_mkdir($child_path, 0775, TRUE), 'No error reported when creating new local directories.', 'File'); // Ensure new directories also exist. - $this->assertTrue(is_dir($parent_path), t('New parent directory actually exists.'), 'File'); - $this->assertTrue(is_dir($child_path), t('New child directory actually exists.'), 'File'); + $this->assertTrue(is_dir($parent_path), 'New parent directory actually exists.', 'File'); + $this->assertTrue(is_dir($child_path), 'New child directory actually exists.', 'File'); // Check that new directory permissions were set properly. $this->assertDirectoryPermissions($parent_path, 0775);