Skip to content
Snippets Groups Projects
Commit 78d37706 authored by Alex Pott's avatar Alex Pott
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
No related branches found
No related tags found
2 merge requests!7452Issue #1797438. HTML5 validation is preventing form submit and not fully...,!789Issue #3210310: Adjust Database API to remove deprecated Drupal 9 code in Drupal 10
...@@ -181,8 +181,10 @@ public function mkdir($uri, $mode = NULL, $recursive = FALSE, $context = NULL) { ...@@ -181,8 +181,10 @@ public function mkdir($uri, $mode = NULL, $recursive = FALSE, $context = NULL) {
// If recursive, create each missing component of the parent directory // If recursive, create each missing component of the parent directory
// individually and set the mode explicitly to override the umask. // individually and set the mode explicitly to override the umask.
if ($recursive) { if ($recursive) {
// Ensure the path is using DIRECTORY_SEPARATOR. // Ensure the path is using DIRECTORY_SEPARATOR, and trim off any trailing
$uri = str_replace('/', DIRECTORY_SEPARATOR, $uri); // 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. // Determine the components of the path.
$components = explode(DIRECTORY_SEPARATOR, $uri); $components = explode(DIRECTORY_SEPARATOR, $uri);
// If the filepath is absolute the first component will be empty as there // If the filepath is absolute the first component will be empty as there
......
...@@ -161,4 +161,17 @@ function testFileDirectoryTemp() { ...@@ -161,4 +161,17 @@ function testFileDirectoryTemp() {
$this->assertEqual($config->get('path.temporary'), $tmp_directory); $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));
}
} }
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment