diff --git a/core/lib/Drupal/Core/Config/FileStorage.php b/core/lib/Drupal/Core/Config/FileStorage.php index 03b0464..382733c 100644 --- a/core/lib/Drupal/Core/Config/FileStorage.php +++ b/core/lib/Drupal/Core/Config/FileStorage.php @@ -207,8 +207,9 @@ public function listAll($prefix = '') { $files = scandir($dir); $names = array(); + $pattern = '/^' . preg_quote($prefix, '/') . '.*' . preg_quote($extension, '/') . '$/'; foreach ($files as $file) { - if ($file[0] !== '.' && fnmatch($prefix . '*' . $extension, $file)) { + if ($file[0] !== '.' && preg_match($pattern, $file)) { $names[] = basename($file, $extension); } } @@ -290,6 +291,7 @@ public function getAllCollectionNames() { */ protected function getAllCollectionNamesHelper($directory) { $collections = array(); + $pattern = '/\.' . preg_quote($this->getFileExtension(), '/') . '$/'; foreach (new \DirectoryIterator($directory) as $fileinfo) { if ($fileinfo->isDir() && !$fileinfo->isDot()) { $collection = $fileinfo->getFilename(); @@ -309,7 +311,7 @@ protected function getAllCollectionNamesHelper($directory) { // collection. // @see \Drupal\Core\Config\FileStorage::listAll() foreach (scandir($directory . '/' . $collection) as $file) { - if ($file[0] !== '.' && fnmatch('*.' . $this->getFileExtension(), $file)) { + if ($file[0] !== '.' && preg_match($pattern, $file)) { $collections[] = $collection; break; } diff --git a/core/lib/Drupal/Core/Config/InstallStorage.php b/core/lib/Drupal/Core/Config/InstallStorage.php index ca96bd7..5f70cd9 100644 --- a/core/lib/Drupal/Core/Config/InstallStorage.php +++ b/core/lib/Drupal/Core/Config/InstallStorage.php @@ -190,6 +190,7 @@ protected function getAllFolders() { */ public function getComponentNames(array $list) { $extension = '.' . $this->getFileExtension(); + $pattern = '/' . preg_quote($extension, '/') . '$/'; $folders = array(); foreach ($list as $extension_object) { // We don't have to use ExtensionDiscovery here because our list of @@ -203,7 +204,7 @@ public function getComponentNames(array $list) { $files = scandir($directory); foreach ($files as $file) { - if ($file[0] !== '.' && fnmatch('*' . $extension, $file)) { + if ($file[0] !== '.' && preg_match($pattern, $file)) { $folders[basename($file, $extension)] = $directory; } } @@ -220,6 +221,7 @@ public function getComponentNames(array $list) { */ public function getCoreNames() { $extension = '.' . $this->getFileExtension(); + $pattern = '/' . preg_quote($extension, '/') . '$/'; $folders = array(); $directory = $this->getCoreFolder(); if (is_dir($directory)) { @@ -230,7 +232,7 @@ public function getCoreNames() { $files = scandir($directory); foreach ($files as $file) { - if ($file[0] !== '.' && fnmatch('*' . $extension, $file)) { + if ($file[0] !== '.' && preg_match($pattern, $file)) { $folders[basename($file, $extension)] = $directory; } } diff --git a/core/modules/ckeditor/src/Plugin/Editor/CKEditor.php b/core/modules/ckeditor/src/Plugin/Editor/CKEditor.php index 8072060..f84054c 100644 --- a/core/modules/ckeditor/src/Plugin/Editor/CKEditor.php +++ b/core/modules/ckeditor/src/Plugin/Editor/CKEditor.php @@ -335,7 +335,7 @@ public function getLangcodes() { // Collect languages included with CKEditor based on file listing. $files = scandir('core/assets/vendor/ckeditor/lang'); foreach ($files as $file) { - if ($file[0] !== '.' && fnmatch('*.js', $file)) { + if ($file[0] !== '.' && preg_match('/\.js$/', $file)) { $langcode = basename($file, '.js'); $langcodes[$langcode] = $langcode; } diff --git a/core/modules/config/src/Tests/Storage/FileStorageTest.php b/core/modules/config/src/Tests/Storage/FileStorageTest.php index fb17f1e..a37f084 100644 --- a/core/modules/config/src/Tests/Storage/FileStorageTest.php +++ b/core/modules/config/src/Tests/Storage/FileStorageTest.php @@ -70,6 +70,12 @@ public function testlistAll() { $config_files = $this->storage->listAll(); $this->assertIdentical($config_files, $expected_files, 'Relative path, two config files found.'); + // @todo https://www.drupal.org/node/2666954 FileStorage::listAll() is + // case-sensitive. However, \Drupal\Core\Config\DatabaseStorage::listAll() + // is case-insensitive. + $this->assertIdentical(['system.performance'], $this->storage->listAll('system'), 'The FileStorage::listAll() with prefix works.'); + $this->assertIdentical([], $this->storage->listAll('System'), 'The FileStorage::listAll() is case sensitive.'); + // Initialize FileStorage with absolute file path. $absolute_path = realpath($this->directory); $storage_absolute_path = new FileStorage($absolute_path); diff --git a/core/modules/migrate/src/MigrateTemplateStorage.php b/core/modules/migrate/src/MigrateTemplateStorage.php index 7124d57..8467ad6 100644 --- a/core/modules/migrate/src/MigrateTemplateStorage.php +++ b/core/modules/migrate/src/MigrateTemplateStorage.php @@ -74,7 +74,7 @@ public function getAllTemplates() { if (file_exists($full_directory)) { $files = scandir($full_directory); foreach ($files as $file) { - if ($file[0] !== '.' && fnmatch('*.yml', $file)) { + if ($file[0] !== '.' && preg_match('/\.yml$/', $file)) { $templates[basename($file, '.yml')] = Yaml::decode(file_get_contents("$full_directory/$file")); } }