[BUGFIX] ResourceCompressor must deal with absolute web paths 82/50782/2
authorMarkus Klein <markus.klein@typo3.org>
Fri, 25 Nov 2016 19:29:55 +0000 (20:29 +0100)
committerWouter Wolters <typo3@wouterwolters.nl>
Tue, 29 Nov 2016 18:17:34 +0000 (19:17 +0100)
ResourceCompressor lacks the ability to compress files which are
registered with their absolute web path (as FormEngine does).
Add a check to resolve such paths correctly.

Resolves: #78803
Releases: master
Change-Id: Id42b0889243e898dfb01a018974e5db51675a15b
Reviewed-on: https://review.typo3.org/50782
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: Joerg Boesche <typo3@joergboesche.de>
Reviewed-by: Benni Mack <benni@typo3.org>
Tested-by: Benni Mack <benni@typo3.org>
Reviewed-by: Wouter Wolters <typo3@wouterwolters.nl>
Tested-by: Wouter Wolters <typo3@wouterwolters.nl>
typo3/sysext/core/Classes/Resource/ResourceCompressor.php

index 91359ef..a8fbffb 100644 (file)
@@ -419,9 +419,16 @@ class ResourceCompressor
      */
     protected function getFilenameFromMainDir($filename)
     {
+        $docRoot = GeneralUtility::getIndpEnv('TYPO3_DOCUMENT_ROOT');
+        $fileNameWithoutSlash = ltrim($filename, '/');
+
+        // if the file exists in the document root
+        if (is_file($docRoot . '/' . $fileNameWithoutSlash)) {
+            return substr($docRoot . '/' . $fileNameWithoutSlash, strlen($this->rootPath));
+        }
         // if the file exists in the root path, just return the $filename
-        if (is_file($this->rootPath . ltrim($filename, '/'))) {
-            return ltrim($filename, '/');
+        if (is_file($this->rootPath . $fileNameWithoutSlash)) {
+            return $fileNameWithoutSlash;
         }
         // if the file is from a special TYPO3 internal directory, add the missing typo3/ prefix
         if (is_file(realpath(PATH_site . TYPO3_mainDir . $filename))) {
@@ -433,7 +440,7 @@ class ResourceCompressor
         } elseif (strpos($filename, '../') === 0) {
             $file = GeneralUtility::resolveBackPath(PATH_typo3 . $filename);
         } else {
-            $file = PATH_site . ltrim($filename, '/');
+            $file = PATH_site . $fileNameWithoutSlash;
         }
 
         // check if the file exists, and if so, return the path relative to TYPO3_mainDir