[BUGFIX] Throw proper exception when parsing Yaml files 97/53197/3
authorBenni Mack <benni@typo3.org>
Tue, 13 Jun 2017 05:50:12 +0000 (07:50 +0200)
committerBenni Mack <benni@typo3.org>
Tue, 13 Jun 2017 13:53:52 +0000 (15:53 +0200)
When having an empty Yaml file, the error that is thrown isn't
helpful for the developer, and in case of RTE, the RTE is not shown
at all.

Resolves: #81557
Releases: master, 8.7
Change-Id: Ie435b9f42623962637a9ead0243be6cde15c82c6
Reviewed-on: https://review.typo3.org/53197
Tested-by: TYPO3com <no-reply@typo3.com>
Reviewed-by: Georg Ringer <georg.ringer@gmail.com>
Tested-by: Georg Ringer <georg.ringer@gmail.com>
Reviewed-by: Josef Glatz <josef.glatz@typo3.org>
Tested-by: Josef Glatz <josef.glatz@typo3.org>
Reviewed-by: Benni Mack <benni@typo3.org>
Tested-by: Benni Mack <benni@typo3.org>
typo3/sysext/core/Classes/Configuration/Loader/YamlFileLoader.php

index d0c5251..2e79e24 100644 (file)
@@ -18,7 +18,7 @@ use Symfony\Component\Yaml\Yaml;
 use TYPO3\CMS\Core\Utility\GeneralUtility;
 
 /**
- * A Yaml file loader that allows to load YML files, based on the Symfony/Yaml component
+ * A Yaml file loader that allows to load YAML files, based on the Symfony/Yaml component
  *
  * In addition to just load a yaml file, it adds some special functionality.
  *
@@ -39,12 +39,17 @@ class YamlFileLoader
      *
      * @param string $fileName either relative to PATH_site or prefixed with EXT:...
      * @return array the configuration as array
+     * @throws \RuntimeException when the file is empty or is of invalid format
      */
     public function load(string $fileName): array
     {
         $content = $this->getFileContents($fileName);
         $content = Yaml::parse($content);
 
+        if (!is_array($content)) {
+            throw new \RuntimeException('YAML file "' . $fileName . '" could not be parsed into valid syntax, probably empty?', 1497332874);
+        }
+
         $content = $this->processImports($content);
 
         // Check for "%" placeholders
@@ -63,11 +68,11 @@ class YamlFileLoader
      */
     protected function getFileContents(string $fileName): string
     {
-        $fileName = GeneralUtility::getFileAbsFileName($fileName);
-        if (!$fileName) {
+        $streamlinedFileName = GeneralUtility::getFileAbsFileName($fileName);
+        if (!$streamlinedFileName) {
             throw new \RuntimeException('YAML File "' . $fileName . '" could not be loaded', 1485784246);
         }
-        return file_get_contents($fileName);
+        return file_get_contents($streamlinedFileName);
     }
 
     /**