[BUGFIX] Allow log files to be outside PATH_site 75/41475/8
authorAndreas Wolf <andreas.wolf@typo3.org>
Thu, 16 Jul 2015 14:54:09 +0000 (16:54 +0200)
committerStefan Neufeind <typo3.neufeind@speedpartner.de>
Sun, 18 Oct 2015 16:21:19 +0000 (18:21 +0200)
Change-Id: I81438b2230a9d3d15dca0c15d14bca3736ca12a3
Resolves: #68231
Releases: master, 6.2
Reviewed-on: http://review.typo3.org/41475
Reviewed-by: Daniel Goerz <ervaude@gmail.com>
Tested-by: Daniel Goerz <ervaude@gmail.com>
Reviewed-by: Stefan Neufeind <typo3.neufeind@speedpartner.de>
Tested-by: Stefan Neufeind <typo3.neufeind@speedpartner.de>
typo3/sysext/core/Classes/Log/Writer/FileWriter.php
typo3/sysext/core/Tests/Unit/Log/Writer/FileWriterTest.php

index 1c0b32e..971373b 100644 (file)
@@ -18,6 +18,7 @@ use TYPO3\CMS\Core\Log\Exception\InvalidLogWriterConfigurationException;
 use TYPO3\CMS\Core\Log\LogLevel;
 use TYPO3\CMS\Core\Log\LogRecord;
 use TYPO3\CMS\Core\Utility\GeneralUtility;
+use TYPO3\CMS\Core\Utility\PathUtility;
 
 /**
  * Log writer that writes the log records into a file.
@@ -75,19 +76,19 @@ class FileWriter extends AbstractWriter
     /**
      * Sets the path to the log file.
      *
-     * @param string $logFile path to the log file, relative to PATH_site
+     * @param string $relativeLogFile path to the log file, relative to PATH_site
      * @return WriterInterface
      * @throws InvalidLogWriterConfigurationException
      */
-    public function setLogFile($logFile)
+    public function setLogFile($relativeLogFile)
     {
-
+       $logFile = $relativeLogFile;
         // Skip handling if logFile is a stream resource. This is used by unit tests with vfs:// directories
-        if (false === strpos($logFile, '://')) {
-            if (!GeneralUtility::isAllowedAbsPath((PATH_site . $logFile))) {
-                throw new InvalidLogWriterConfigurationException('Log file path "' . $logFile . '" is not valid!', 1326411176);
-            }
+        if (false === strpos($logFile, '://') && !PathUtility::isAbsolutePath($logFile)) {
             $logFile = GeneralUtility::getFileAbsFileName($logFile);
+            if ($logFile === NULL) {
+                throw new InvalidLogWriterConfigurationException('Log file path "' . $relativeLogFile . '" is not valid!', 1444374805);
+            }
         }
         $this->logFile = $logFile;
         $this->openLogFile();
index ad8db50..654a3c5 100644 (file)
@@ -93,12 +93,12 @@ class FileWriterTest extends \TYPO3\CMS\Core\Tests\UnitTestCase
 
     /**
      * @test
-     * @expectedException \TYPO3\CMS\Core\Log\Exception\InvalidLogWriterConfigurationException
      */
-    public function setLogFileRefusesIllegalPath()
+    public function setLogFileAcceptsAbsolutePath()
     {
         $writer = \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance(\TYPO3\CMS\Core\Log\Writer\FileWriter::class);
         $writer->setLogFile('/tmp/typo3.log');
+        $this->assertAttributeEquals('/tmp/typo3.log', 'logFile', $writer);
     }
 
     /**