Skip to content
Snippets Groups Projects
Commit 863b2b35 authored by catch's avatar catch
Browse files

Issue #3167036 by gapple, anu.a_zyxware, thalles, larowlan: Empty...

Issue #3167036 by gapple, anu.a_zyxware, thalles, larowlan: Empty *.libraries.yml file can cause fatal error
parent 15de0783
No related branches found
No related tags found
No related merge requests found
......@@ -341,7 +341,7 @@ protected function parseLibraryInfo($extension, $path) {
$library_file = $path . '/' . $extension . '.libraries.yml';
if (file_exists($this->root . '/' . $library_file)) {
try {
$libraries = Yaml::decode(file_get_contents($this->root . '/' . $library_file));
$libraries = Yaml::decode(file_get_contents($this->root . '/' . $library_file)) ?? [];
}
catch (InvalidDataTypeException $e) {
// Rethrow a more helpful exception to provide context.
......
......@@ -644,6 +644,24 @@ public function testNonCoreLibrariesNotFound() {
$this->assertEquals('libraries/third_party_library/css/example.css', $library['css'][0]['data']);
}
/**
* @covers ::parseLibraryInfo
*/
public function testEmptyLibraryFile() {
$this->moduleHandler->expects($this->atLeastOnce())
->method('moduleExists')
->with('empty')
->will($this->returnValue(TRUE));
$path = __DIR__ . '/library_test_files';
$path = substr($path, strlen($this->root) + 1);
$this->libraryDiscoveryParser->setPaths('module', 'empty', $path);
$libraries = $this->libraryDiscoveryParser->buildByExtension('empty');
$this->assertEquals([], $libraries);
}
}
/**
......
# This file intentionally left empty
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