Commit 78d37706 authored by alexpott's avatar alexpott
Browse files

Issue #2818031 by phenaproxima, Berdir, alexpott: Trailing slashes can cause...

Issue #2818031 by phenaproxima, Berdir, alexpott: Trailing slashes can cause FileSystem::mkdir() to return a false negative
parent e276eeb1
......@@ -181,8 +181,10 @@ public function 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);
// Ensure the path is using DIRECTORY_SEPARATOR, and trim off any trailing
// slashes because they can throw off the loop when creating the parent
// directories.
$uri = rtrim(str_replace('/', DIRECTORY_SEPARATOR, $uri), DIRECTORY_SEPARATOR);
// Determine the components of the path.
$components = explode(DIRECTORY_SEPARATOR, $uri);
// If the filepath is absolute the first component will be empty as there
......
......@@ -161,4 +161,17 @@ function testFileDirectoryTemp() {
$this->assertEqual($config->get('path.temporary'), $tmp_directory);
}
/**
* Tests directory creation.
*/
public function testDirectoryCreation() {
/** @var \Drupal\Core\File\FileSystemInterface $file_system */
$file_system = $this->container->get('file_system');
// mkdir() recursion should work with or without a trailing slash.
$dir = $this->siteDirectory . '/files';
$this->assertTrue($file_system->mkdir($dir . '/foo/bar', 0775, TRUE));
$this->assertTrue($file_system->mkdir($dir . '/foo/baz/', 0775, TRUE));
}
}
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment