diff --git a/typo3/sysext/core/Classes/Resource/ResourceCompressor.php b/typo3/sysext/core/Classes/Resource/ResourceCompressor.php
index 26d2cf147b4aab71acb86fbe64ba90c29b29e274..0543b9bacf5572409f995efef83f4c94d047ebd4 100644
--- a/typo3/sysext/core/Classes/Resource/ResourceCompressor.php
+++ b/typo3/sysext/core/Classes/Resource/ResourceCompressor.php
@@ -462,7 +462,7 @@ class ResourceCompressor
         } elseif (strpos($filename, '../') === 0) {
             $file = GeneralUtility::resolveBackPath(PATH_typo3 . $filename);
         } else {
-            $file = PATH_site . $fileNameWithoutSlash;
+            $file = PATH_site . $filename;
         }
 
         // check if the file exists, and if so, return the path relative to TYPO3_mainDir
diff --git a/typo3/sysext/core/Tests/Unit/Resource/ResourceCompressorIntegrationTest.php b/typo3/sysext/core/Tests/Unit/Resource/ResourceCompressorIntegrationTest.php
new file mode 100644
index 0000000000000000000000000000000000000000..c493bb568f76759b1e4657ca1950d656414aba03
--- /dev/null
+++ b/typo3/sysext/core/Tests/Unit/Resource/ResourceCompressorIntegrationTest.php
@@ -0,0 +1,132 @@
+<?php
+
+namespace TYPO3\CMS\Core\Tests\Unit\Resource;
+
+/*
+ * This file is part of the TYPO3 CMS project.
+ *
+ * It is free software; you can redistribute it and/or modify it under
+ * the terms of the GNU General Public License, either version 2
+ * of the License, or any later version.
+ *
+ * For the full copyright and license information, please read the
+ * LICENSE.txt file that was distributed with this source code.
+ *
+ * The TYPO3 project - inspiring people to share!
+ */
+
+use TYPO3\CMS\Core\Tests\Unit\Resource\ResourceCompressorTest\Fixtures\TestableResourceCompressor;
+use TYPO3\CMS\Core\Utility\GeneralUtility;
+
+/**
+ * Testcase for the ResourceCompressor class
+ */
+class ResourceCompressorIntegrationTest extends BaseTestCase
+{
+
+    /**
+     * @var TestableResourceCompressor
+     */
+    protected $resourceCompressor;
+
+    /**
+     * @var string
+     */
+    protected $fixtureDir;
+
+    /**
+     * @var string
+     */
+    protected $fixtureDirFromTest;
+
+    public function setUp()
+    {
+        $this->fixtureDir = 'sysext/core/Tests/Unit/Resource/ResourceCompressorTest/Fixtures/';
+        $this->fixtureDirFromTest = GeneralUtility::fixWindowsFilePath(__DIR__ . '/ResourceCompressorTest/Fixtures/');
+    }
+
+    /**
+     * @test
+     */
+    public function constructorCreatesTargetDirectory()
+    {
+        $this->resourceCompressor = new TestableResourceCompressor();
+        $dir = PATH_site . $this->resourceCompressor->getTargetDirectory();
+        self::assertFileExists($dir);
+    }
+
+    /**
+     * @test
+     */
+    public function constructorCreatesHtaccessFileIfSet()
+    {
+        $GLOBALS['TYPO3_CONF_VARS']['SYS']['generateApacheHtaccess'] = true;
+        $this->resourceCompressor = new TestableResourceCompressor();
+        $htaccessPath = PATH_site . $this->resourceCompressor->getTargetDirectory() . '.htaccess';
+        self::assertStringEqualsFile($htaccessPath, $this->resourceCompressor->getHtaccessTemplate());
+    }
+
+    /**
+     * @test
+     */
+    public function constructorDoesNotCreateHtaccessFileIfSetToFalse()
+    {
+        $GLOBALS['TYPO3_CONF_VARS']['SYS']['generateApacheHtaccess'] = false;
+        $this->resourceCompressor = new TestableResourceCompressor();
+        $htaccessPath = PATH_site . $this->resourceCompressor->getTargetDirectory() . '.htaccess';
+        self::assertFileNotExists($htaccessPath);
+    }
+
+    /**
+     * @test
+     */
+    public function concatenateCssFiles()
+    {
+        $files = [
+            'sampleFile1' => [
+                'excludeFromConcatenation' => false,
+                'file' => $this->fixtureDir . 'css_input_with_import.css',
+                'media' => 'screen',
+                'forceOnTop' => false,
+            ],
+        ];
+        $this->resourceCompressor = new TestableResourceCompressor();
+        $concatFiles = $this->resourceCompressor->concatenateCssFiles($files);
+        $mergedFile = array_pop($concatFiles);
+        $expected = file_get_contents(
+            $this->fixtureDirFromTest . 'expected' . DIRECTORY_SEPARATOR . 'merged-css_input_with_import.css'
+        );
+        self::assertStringEqualsFile(GeneralUtility::fixWindowsFilePath(PATH_site . $mergedFile['file']), $expected);
+    }
+
+    /**
+     * @test
+     */
+    public function concatenateCssFilesWorksWithFileFromNonRootPath()
+    {
+        $testFile = PATH_site . 'typo3temp/var/transient/css_input_with_import.css';
+        $this->testFilesToDelete[] = $testFile;
+        copy(PATH_typo3 . $this->fixtureDir . 'css_input_with_import.css', $testFile);
+        $files = [
+            'sampleFile1' => [
+                'excludeFromConcatenation' => false,
+                'file' => 'typo3temp/var/transient/css_input_with_import.css',
+                'media' => 'screen',
+                'forceOnTop' => false,
+            ],
+        ];
+        $this->resourceCompressor = new TestableResourceCompressor();
+        $concatFiles = $this->resourceCompressor->concatenateCssFiles($files);
+        $mergedFile = array_pop($concatFiles);
+        $expected = file_get_contents(
+            $this->fixtureDirFromTest . 'expected' . DIRECTORY_SEPARATOR . 'merged-css_input_with_import_non_root.css'
+        );
+        self::assertStringEqualsFile(GeneralUtility::fixWindowsFilePath(PATH_site . $mergedFile['file']), $expected);
+    }
+
+    public function tearDown()
+    {
+        $this->testFilesToDelete[] = PATH_site . $this->resourceCompressor->getTargetDirectory();
+        parent::tearDown();
+    }
+}
diff --git a/typo3/sysext/core/Tests/Unit/Resource/ResourceCompressorTest/Fixtures/TestableResourceCompressor.php b/typo3/sysext/core/Tests/Unit/Resource/ResourceCompressorTest/Fixtures/TestableResourceCompressor.php
new file mode 100644
index 0000000000000000000000000000000000000000..d30c811a686bda22bba70218417bdd7e53651942
--- /dev/null
+++ b/typo3/sysext/core/Tests/Unit/Resource/ResourceCompressorTest/Fixtures/TestableResourceCompressor.php
@@ -0,0 +1,34 @@
+<?php
+declare(strict_types=1);
+
+namespace TYPO3\CMS\Core\Tests\Unit\Resource\ResourceCompressorTest\Fixtures;
+
+/*
+ * This file is part of the TYPO3 CMS project.
+ *
+ * It is free software; you can redistribute it and/or modify it under
+ * the terms of the GNU General Public License, either version 2
+ * of the License, or any later version.
+ *
+ * For the full copyright and license information, please read the
+ * LICENSE.txt file that was distributed with this source code.
+ *
+ * The TYPO3 project - inspiring people to share!
+ */
+
+use TYPO3\CMS\Core\Resource\ResourceCompressor;
+
+class TestableResourceCompressor extends ResourceCompressor
+{
+    protected $targetDirectory = 'typo3temp/var/tests/resource/';
+
+    public function getTargetDirectory()
+    {
+        return $this->targetDirectory;
+    }
+
+    public function getHtaccessTemplate()
+    {
+        return $this->htaccessTemplate;
+    }
+}
diff --git a/typo3/sysext/core/Tests/Unit/Resource/ResourceCompressorTest/Fixtures/expected/merged-css_input_with_import.css b/typo3/sysext/core/Tests/Unit/Resource/ResourceCompressorTest/Fixtures/expected/merged-css_input_with_import.css
new file mode 100644
index 0000000000000000000000000000000000000000..c9f1f2dfaf265d31d8a25231f2f50e27e0a3ebdf
--- /dev/null
+++ b/typo3/sysext/core/Tests/Unit/Resource/ResourceCompressorTest/Fixtures/expected/merged-css_input_with_import.css
@@ -0,0 +1,28 @@
+
+/* moved by compressor */
+@import "../../../typo3/sysext/core/Tests/Unit/Resource/ResourceCompressorTest/Fixtures/import1.css";@import "../../../typo3/sysext/core/Tests/Unit/Resource/ResourceCompressorTest/Fixtures/import2.css";@import url("http://example.com/style.css");@import url("//example.com/style.css");
+/* moved by compressor */
+body {
+  margin: 0;
+  padding: 0;
+  background: #edf5fa;
+  font: 76%/170% Verdana, sans-serif;
+  color: #494949;
+}
+
+.this .is .a .test {
+  font: 1em/100% Verdana, sans-serif;
+  color: #494949;
+}
+.this
+.is
+.a
+.test {
+font: 1em/100% Verdana, sans-serif;
+color: #494949;
+}
+
+textarea, select {
+  font: 1em/160% Verdana, sans-serif;
+  color: #494949;
+}
\ No newline at end of file
diff --git a/typo3/sysext/core/Tests/Unit/Resource/ResourceCompressorTest/Fixtures/expected/merged-css_input_with_import_non_root.css b/typo3/sysext/core/Tests/Unit/Resource/ResourceCompressorTest/Fixtures/expected/merged-css_input_with_import_non_root.css
new file mode 100644
index 0000000000000000000000000000000000000000..eba30c48bdb58f35df69238f8e28b41061b1818e
--- /dev/null
+++ b/typo3/sysext/core/Tests/Unit/Resource/ResourceCompressorTest/Fixtures/expected/merged-css_input_with_import_non_root.css
@@ -0,0 +1,28 @@
+
+/* moved by compressor */
+@import "../../../typo3temp/var/transient/import1.css";@import "../../../typo3temp/var/transient/import2.css";@import url("http://example.com/style.css");@import url("//example.com/style.css");
+/* moved by compressor */
+body {
+  margin: 0;
+  padding: 0;
+  background: #edf5fa;
+  font: 76%/170% Verdana, sans-serif;
+  color: #494949;
+}
+
+.this .is .a .test {
+  font: 1em/100% Verdana, sans-serif;
+  color: #494949;
+}
+.this
+.is
+.a
+.test {
+font: 1em/100% Verdana, sans-serif;
+color: #494949;
+}
+
+textarea, select {
+  font: 1em/160% Verdana, sans-serif;
+  color: #494949;
+}
\ No newline at end of file