From f13b3b6651b81d1bd4a314ce1e66e164e9ac5f1d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?John=20Molakvo=C3=A6=20=28skjnldsv=29?= Date: Wed, 27 Dec 2017 11:00:46 +0100 Subject: [PATCH 01/15] Fixed scss url rewriting MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: John Molakvoæ (skjnldsv) --- lib/private/Template/SCSSCacher.php | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/lib/private/Template/SCSSCacher.php b/lib/private/Template/SCSSCacher.php index c4ec5f95dc743..cfe0e60523daf 100644 --- a/lib/private/Template/SCSSCacher.php +++ b/lib/private/Template/SCSSCacher.php @@ -2,6 +2,13 @@ /** * @copyright Copyright (c) 2016, John Molakvoæ (skjnldsv@protonmail.com) * + * @author John Molakvoæ (skjnldsv) + * @author Julius Haertl + * @author Julius Härtl + * @author Lukas Reschke + * @author Morris Jobke + * @author Roeland Jago Douma + * * @license GNU AGPL version 3 or any later version * * This program is free software: you can redistribute it and/or modify @@ -276,12 +283,7 @@ private function getInjectedVariables() { */ private function rebaseUrls($css, $webDir) { $re = '/url\([\'"]([\.\w?=\/-]*)[\'"]\)/x'; - // OC\Route\Router:75 - if(($this->config->getSystemValue('htaccess.IgnoreFrontController', false) === true || getenv('front_controller_active') === 'true')) { - $subst = 'url(\'../../'.$webDir.'/$1\')'; - } else { - $subst = 'url(\'../../../'.$webDir.'/$1\')'; - } + $subst = 'url(\''.$webDir.'/$1\')'; return preg_replace($re, $subst, $css); } @@ -292,6 +294,7 @@ private function rebaseUrls($css, $webDir) { * @return string */ public function getCachedSCSS($appName, $fileName) { + //var_dump([$appName, $fileName]); $tmpfileLoc = explode('/', $fileName); $fileName = array_pop($tmpfileLoc); $fileName = $this->prependBaseurlPrefix(str_replace('.scss', '.css', $fileName)); From 00412d1c8ce7c699a83740d20209bd3e0bdda906 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?John=20Molakvo=C3=A6=20=28skjnldsv=29?= Date: Wed, 27 Dec 2017 11:01:27 +0100 Subject: [PATCH 02/15] Fixed webroot for scss files Fixed tests MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: John Molakvoæ (skjnldsv) --- lib/private/Template/CSSResourceLocator.php | 4 ++-- lib/private/Template/SCSSCacher.php | 18 +++++++++++++++--- tests/lib/Template/SCSSCacherTest.php | 13 ++----------- 3 files changed, 19 insertions(+), 16 deletions(-) diff --git a/lib/private/Template/CSSResourceLocator.php b/lib/private/Template/CSSResourceLocator.php index d5e9ce732cc97..2226f4f6a39c2 100644 --- a/lib/private/Template/CSSResourceLocator.php +++ b/lib/private/Template/CSSResourceLocator.php @@ -104,7 +104,7 @@ protected function cacheAndAppendScssIfExist($root, $file, $app = 'core') { if($this->scssCacher !== null) { if($this->scssCacher->process($root, $file, $app)) { - $this->append($root, $this->scssCacher->getCachedSCSS($app, $file), false, true, true); + $this->append($root, $this->scssCacher->getCachedSCSS($app, $file), \OC::$WEBROOT, true, true); return true; } else { $this->logger->warning('Failed to compile and/or save '.$root.'/'.$file, ['app' => 'core']); @@ -141,7 +141,7 @@ public function append($root, $file, $webRoot = null, $throw = true, $scss = fal } } - $this->resources[] = array($webRoot? : '/', $webRoot, $file); + $this->resources[] = array($webRoot? : \OC::$WEBROOT, $webRoot, $file); } } } diff --git a/lib/private/Template/SCSSCacher.php b/lib/private/Template/SCSSCacher.php index cfe0e60523daf..9b41aae11d7fe 100644 --- a/lib/private/Template/SCSSCacher.php +++ b/lib/private/Template/SCSSCacher.php @@ -102,8 +102,21 @@ public function process($root, $file, $app) { $fileNameCSS = $this->prependBaseurlPrefix(str_replace('.scss', '.css', $fileNameSCSS)); $path = implode('/', $path); - - $webDir = substr($path, strlen($this->serverRoot)+1); + $webDir = null; + + // Detect if path is within an app path + $app_paths = $this->config->getSystemValue('apps_paths'); + if (!empty($app_paths)) { + foreach ($app_paths as $app_path) { + if (strpos($path, $app_path["path"]) === 0) { + $webDir = $app_path["url"].str_replace($app_path["path"], '', $path); + break; + } + } + } + if (is_null($webDir)) { + $webDir = substr($path, strlen($this->serverRoot)); + } try { $folder = $this->appData->getFolder($app); @@ -294,7 +307,6 @@ private function rebaseUrls($css, $webDir) { * @return string */ public function getCachedSCSS($appName, $fileName) { - //var_dump([$appName, $fileName]); $tmpfileLoc = explode('/', $fileName); $fileName = array_pop($tmpfileLoc); $fileName = $this->prependBaseurlPrefix(str_replace('.scss', '.css', $fileName)); diff --git a/tests/lib/Template/SCSSCacherTest.php b/tests/lib/Template/SCSSCacherTest.php index 345972bb1afd6..1df8e86f93ca5 100644 --- a/tests/lib/Template/SCSSCacherTest.php +++ b/tests/lib/Template/SCSSCacherTest.php @@ -352,19 +352,10 @@ public function testCacheFailure() { } public function testRebaseUrls() { - $webDir = 'apps/files/css'; + $webDir = '/apps/files/css'; $css = '#id { background-image: url(\'../img/image.jpg\'); }'; $actual = self::invokePrivate($this->scssCacher, 'rebaseUrls', [$css, $webDir]); - $expected = '#id { background-image: url(\'../../../apps/files/css/../img/image.jpg\'); }'; - $this->assertEquals($expected, $actual); - } - - public function testRebaseUrlsIgnoreFrontendController() { - $this->config->expects($this->once())->method('getSystemValue')->with('htaccess.IgnoreFrontController', false)->willReturn(true); - $webDir = 'apps/files/css'; - $css = '#id { background-image: url(\'../img/image.jpg\'); }'; - $actual = self::invokePrivate($this->scssCacher, 'rebaseUrls', [$css, $webDir]); - $expected = '#id { background-image: url(\'../../apps/files/css/../img/image.jpg\'); }'; + $expected = '#id { background-image: url(\'/apps/files/css/../img/image.jpg\'); }'; $this->assertEquals($expected, $actual); } From 5008eb8f8577f97853408a0cab3a03b1807cad54 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?John=20Molakvo=C3=A6=20=28skjnldsv=29?= Date: Wed, 27 Dec 2017 16:44:14 +0100 Subject: [PATCH 03/15] getWebDir function MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: John Molakvoæ (skjnldsv) --- lib/private/Template/SCSSCacher.php | 34 ++++++++++++++++------------- 1 file changed, 19 insertions(+), 15 deletions(-) diff --git a/lib/private/Template/SCSSCacher.php b/lib/private/Template/SCSSCacher.php index 9b41aae11d7fe..80fa116470bca 100644 --- a/lib/private/Template/SCSSCacher.php +++ b/lib/private/Template/SCSSCacher.php @@ -102,21 +102,7 @@ public function process($root, $file, $app) { $fileNameCSS = $this->prependBaseurlPrefix(str_replace('.scss', '.css', $fileNameSCSS)); $path = implode('/', $path); - $webDir = null; - - // Detect if path is within an app path - $app_paths = $this->config->getSystemValue('apps_paths'); - if (!empty($app_paths)) { - foreach ($app_paths as $app_path) { - if (strpos($path, $app_path["path"]) === 0) { - $webDir = $app_path["url"].str_replace($app_path["path"], '', $path); - break; - } - } - } - if (is_null($webDir)) { - $webDir = substr($path, strlen($this->serverRoot)); - } + $webDir = $this->getWebDir($path); try { $folder = $this->appData->getFolder($app); @@ -322,4 +308,22 @@ public function getCachedSCSS($appName, $fileName) { private function prependBaseurlPrefix($cssFile) { return md5($this->urlGenerator->getBaseUrl()) . '-' . $cssFile; } + + /** + * Prepend hashed base url to the css file + * @param string $path the css file path + * @return string the webDir + */ + private function getWebDir($path) { + // Detect if path is within an app path + $app_paths = $this->config->getSystemValue('apps_paths'); + if (!empty($app_paths)) { + foreach ($app_paths as $app_path) { + if (strpos($path, $app_path["path"]) === 0) { + return $app_path["url"].str_replace($app_path["path"], '', $path); + } + } + } + return substr($path, strlen($this->serverRoot)); + } } From 89b6bc9424060e72abaf5b20a5ca531aca74c03f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?John=20Molakvo=C3=A6=20=28skjnldsv=29?= Date: Thu, 28 Dec 2017 10:25:10 +0100 Subject: [PATCH 04/15] Use OC_Util function for app web path MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: John Molakvoæ (skjnldsv) --- lib/private/Template/SCSSCacher.php | 25 ++++++++++++++----------- 1 file changed, 14 insertions(+), 11 deletions(-) diff --git a/lib/private/Template/SCSSCacher.php b/lib/private/Template/SCSSCacher.php index 80fa116470bca..8da4d51b749b5 100644 --- a/lib/private/Template/SCSSCacher.php +++ b/lib/private/Template/SCSSCacher.php @@ -102,7 +102,7 @@ public function process($root, $file, $app) { $fileNameCSS = $this->prependBaseurlPrefix(str_replace('.scss', '.css', $fileNameSCSS)); $path = implode('/', $path); - $webDir = $this->getWebDir($path); + $webDir = $this->getWebDir($path, $app); try { $folder = $this->appData->getFolder($app); @@ -310,20 +310,23 @@ private function prependBaseurlPrefix($cssFile) { } /** - * Prepend hashed base url to the css file + * Get WebDir root * @param string $path the css file path + * @param string $app the app name * @return string the webDir */ - private function getWebDir($path) { + private function getWebDir($path, $app) { + // Detect if path is within server root + if(strpos($path, $this->serverRoot) > -1) { + return \OC::$WEBROOT.substr($path, strlen($this->serverRoot)); + } // Detect if path is within an app path - $app_paths = $this->config->getSystemValue('apps_paths'); - if (!empty($app_paths)) { - foreach ($app_paths as $app_path) { - if (strpos($path, $app_path["path"]) === 0) { - return $app_path["url"].str_replace($app_path["path"], '', $path); - } - } + if($appWebPath = \OC_App::getAppWebPath($app)) { + // Get the file path within the app directory + $appDirectoryPath = explode($app, $path)[1]; + // Remove the webroot + return str_replace(\OC::$WEBROOT, '', $appWebPath.$appDirectoryPath); } - return substr($path, strlen($this->serverRoot)); + return \OC::$WEBROOT.substr($path, strlen($this->serverRoot)); } } From a46d45a652b60cb2bcbb9261db864589bdd1689b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?John=20Molakvo=C3=A6=20=28skjnldsv=29?= Date: Thu, 28 Dec 2017 10:28:16 +0100 Subject: [PATCH 05/15] Fixup! getWebdir return MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: John Molakvoæ (skjnldsv) --- lib/private/Template/SCSSCacher.php | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) diff --git a/lib/private/Template/SCSSCacher.php b/lib/private/Template/SCSSCacher.php index 8da4d51b749b5..2f63b425a1e82 100644 --- a/lib/private/Template/SCSSCacher.php +++ b/lib/private/Template/SCSSCacher.php @@ -316,12 +316,8 @@ private function prependBaseurlPrefix($cssFile) { * @return string the webDir */ private function getWebDir($path, $app) { - // Detect if path is within server root - if(strpos($path, $this->serverRoot) > -1) { - return \OC::$WEBROOT.substr($path, strlen($this->serverRoot)); - } - // Detect if path is within an app path - if($appWebPath = \OC_App::getAppWebPath($app)) { + // Detect if path is within server root AND if path is within an app path + if ( strpos($path, $this->serverRoot) === -1 && $appWebPath = \OC_App::getAppWebPath($app) ) { // Get the file path within the app directory $appDirectoryPath = explode($app, $path)[1]; // Remove the webroot From 87b1839cd1f713bb50c4491ddc8714e6331c8cbd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?John=20Molakvo=C3=A6=20=28skjnldsv=29?= Date: Thu, 28 Dec 2017 13:32:45 +0100 Subject: [PATCH 06/15] Added tests for various installations types - With root installation - Core css - App inside server root - Secondary apps directory outside server root - With an installation in a sub directory - Core css - App inside server root - Secondary apps directory outside server root MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: John Molakvoæ (skjnldsv) --- lib/private/Template/SCSSCacher.php | 18 +++++++------ tests/lib/Template/SCSSCacherTest.php | 37 +++++++++++++++++++++++++++ 2 files changed, 47 insertions(+), 8 deletions(-) diff --git a/lib/private/Template/SCSSCacher.php b/lib/private/Template/SCSSCacher.php index 2f63b425a1e82..5b904bced65ef 100644 --- a/lib/private/Template/SCSSCacher.php +++ b/lib/private/Template/SCSSCacher.php @@ -102,7 +102,7 @@ public function process($root, $file, $app) { $fileNameCSS = $this->prependBaseurlPrefix(str_replace('.scss', '.css', $fileNameSCSS)); $path = implode('/', $path); - $webDir = $this->getWebDir($path, $app); + $webDir = $this->getWebDir($path, $app, $this->serverRoot, \OC::$WEBROOT); try { $folder = $this->appData->getFolder($app); @@ -187,7 +187,7 @@ private function cache($path, $fileNameCSS, $fileNameSCSS, ISimpleFolder $folder $scss = new Compiler(); $scss->setImportPaths([ $path, - \OC::$SERVERROOT . '/core/css/', + $this->serverRoot . '/core/css/', ]); // Continue after throw $scss->setIgnoreErrors(true); @@ -312,17 +312,19 @@ private function prependBaseurlPrefix($cssFile) { /** * Get WebDir root * @param string $path the css file path - * @param string $app the app name + * @param string $appName the app name + * @param string $serverRoot the server root path + * @param string $webRoot the nextcloud installation root path * @return string the webDir */ - private function getWebDir($path, $app) { + private function getWebDir($path, $appName, $serverRoot, $webRoot) { // Detect if path is within server root AND if path is within an app path - if ( strpos($path, $this->serverRoot) === -1 && $appWebPath = \OC_App::getAppWebPath($app) ) { + if ( !strpos($path, $serverRoot) && $appWebPath = \OC_App::getAppWebPath($appName) ) { // Get the file path within the app directory - $appDirectoryPath = explode($app, $path)[1]; + $appDirectoryPath = explode($appName, $path)[1]; // Remove the webroot - return str_replace(\OC::$WEBROOT, '', $appWebPath.$appDirectoryPath); + return str_replace($webRoot, '', $appWebPath.$appDirectoryPath); } - return \OC::$WEBROOT.substr($path, strlen($this->serverRoot)); + return $webRoot.substr($path, strlen($serverRoot)); } } diff --git a/tests/lib/Template/SCSSCacherTest.php b/tests/lib/Template/SCSSCacherTest.php index 1df8e86f93ca5..97a2879c94218 100644 --- a/tests/lib/Template/SCSSCacherTest.php +++ b/tests/lib/Template/SCSSCacherTest.php @@ -384,4 +384,41 @@ public function testGetCachedSCSS($appName, $fileName, $result) { $this->assertEquals(substr($result, 1), $actual); } + public function dataGetWebDir() { + return [ + ['/http/core/css', 'core', '', '/http', '/core/css'], + ['/http/apps/test/css', 'test', '', '/http', '/apps/test/css'], + ['/http/nextcloud/core/css', 'core', '/nextcloud', '/http/nextcloud', '/nextcloud/core/css'], + ['/http/nextcloud/apps/test/css', 'test', '/nextcloud', '/http/nextcloud', '/nextcloud/apps/test/css'], + ['/srv/apps2/test/css', 'test', '', '/http', '/apps2/test/css'], + ['/srv/apps2/test/css', 'test', '/nextcloud', '/http/nextcloud', '/apps2/test/css'] + ]; + } + + private function randomString() { + return sha1(uniqid(mt_rand(), true)); + } + + /** + * @param $path + * @param $appName + * @param $webRoot + * @param $serverRoot + * @dataProvider dataGetWebDir + */ + public function testgetWebDir($path, $appName, $webRoot, $serverRoot, $correctWebDir) { + $tmpDir = sys_get_temp_dir().'/'.$this->randomString(); + // Adding fake apps folder and create fake app install + \OC::$APPSROOTS[] = [ + 'path' => $tmpDir.'/srv/apps2', + 'url' => '/apps2', + 'writable' => false + ]; + mkdir($tmpDir.$path, 0777, true); + $actual = self::invokePrivate($this->scssCacher, 'getWebDir', [$tmpDir.$path, $appName, $tmpDir.$serverRoot, $webRoot]); + $this->assertEquals($correctWebDir, $actual); + array_pop(\OC::$APPSROOTS); + rmdir($tmpDir.$path); + } + } From 9fa49c7f24a591567c1d829e53796b32e6268f13 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?John=20Molakvo=C3=A6=20=28skjnldsv=29?= Date: Thu, 28 Dec 2017 13:41:38 +0100 Subject: [PATCH 07/15] Correctly remove temp test directory tree MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: John Molakvoæ (skjnldsv) --- tests/lib/Template/SCSSCacherTest.php | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/tests/lib/Template/SCSSCacherTest.php b/tests/lib/Template/SCSSCacherTest.php index 97a2879c94218..712c00262d68c 100644 --- a/tests/lib/Template/SCSSCacherTest.php +++ b/tests/lib/Template/SCSSCacherTest.php @@ -399,6 +399,18 @@ private function randomString() { return sha1(uniqid(mt_rand(), true)); } + private function rrmdir($directory) { + $files = array_diff(scandir($directory), array('.','..')); + foreach ($files as $file) { + if (is_dir($directory . '/' . $file)) { + $this->rrmdir($directory . '/' . $file); + } else { + unlink($directory . '/' . $file); + } + } + return rmdir($directory); + } + /** * @param $path * @param $appName @@ -418,7 +430,7 @@ public function testgetWebDir($path, $appName, $webRoot, $serverRoot, $correctWe $actual = self::invokePrivate($this->scssCacher, 'getWebDir', [$tmpDir.$path, $appName, $tmpDir.$serverRoot, $webRoot]); $this->assertEquals($correctWebDir, $actual); array_pop(\OC::$APPSROOTS); - rmdir($tmpDir.$path); + $this->rrmdir($tmpDir.$path); } } From 1ae126a78155c297f156f8459142e815a23bbe35 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?John=20Molakvo=C3=A6=20=28skjnldsv=29?= Date: Thu, 28 Dec 2017 14:19:13 +0100 Subject: [PATCH 08/15] Fixed tests MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: John Molakvoæ (skjnldsv) --- lib/private/Template/SCSSCacher.php | 2 +- tests/lib/LegacyHelperTest.php | 11 +++++++++++ tests/lib/Template/SCSSCacherTest.php | 24 +++++++++++++----------- tests/lib/UrlGeneratorTest.php | 10 ++++++++-- 4 files changed, 33 insertions(+), 14 deletions(-) diff --git a/lib/private/Template/SCSSCacher.php b/lib/private/Template/SCSSCacher.php index 5b904bced65ef..542ca1688f556 100644 --- a/lib/private/Template/SCSSCacher.php +++ b/lib/private/Template/SCSSCacher.php @@ -319,7 +319,7 @@ private function prependBaseurlPrefix($cssFile) { */ private function getWebDir($path, $appName, $serverRoot, $webRoot) { // Detect if path is within server root AND if path is within an app path - if ( !strpos($path, $serverRoot) && $appWebPath = \OC_App::getAppWebPath($appName) ) { + if ( strpos($path, $serverRoot) === false && $appWebPath = \OC_App::getAppWebPath($appName)) { // Get the file path within the app directory $appDirectoryPath = explode($appName, $path)[1]; // Remove the webroot diff --git a/tests/lib/LegacyHelperTest.php b/tests/lib/LegacyHelperTest.php index f1e22ea600ecb..736c5bf7fad78 100644 --- a/tests/lib/LegacyHelperTest.php +++ b/tests/lib/LegacyHelperTest.php @@ -12,6 +12,17 @@ use OC_Helper; class LegacyHelperTest extends \Test\TestCase { + /** @var string */ + private $originalWebRoot; + + public function setUp() { + $this->originalWebRoot = \OC::$WEBROOT; + } + + public function tearDown() { + // Reset webRoot + \OC::$WEBROOT = $this->originalWebRoot; + } /** * @dataProvider humanFileSizeProvider diff --git a/tests/lib/Template/SCSSCacherTest.php b/tests/lib/Template/SCSSCacherTest.php index 712c00262d68c..1c915fd690ca1 100644 --- a/tests/lib/Template/SCSSCacherTest.php +++ b/tests/lib/Template/SCSSCacherTest.php @@ -384,17 +384,6 @@ public function testGetCachedSCSS($appName, $fileName, $result) { $this->assertEquals(substr($result, 1), $actual); } - public function dataGetWebDir() { - return [ - ['/http/core/css', 'core', '', '/http', '/core/css'], - ['/http/apps/test/css', 'test', '', '/http', '/apps/test/css'], - ['/http/nextcloud/core/css', 'core', '/nextcloud', '/http/nextcloud', '/nextcloud/core/css'], - ['/http/nextcloud/apps/test/css', 'test', '/nextcloud', '/http/nextcloud', '/nextcloud/apps/test/css'], - ['/srv/apps2/test/css', 'test', '', '/http', '/apps2/test/css'], - ['/srv/apps2/test/css', 'test', '/nextcloud', '/http/nextcloud', '/apps2/test/css'] - ]; - } - private function randomString() { return sha1(uniqid(mt_rand(), true)); } @@ -411,6 +400,19 @@ private function rrmdir($directory) { return rmdir($directory); } + public function dataGetWebDir() { + return [ + // Root installation + ['/http/core/css', 'core', '', '/http', '/core/css'], + ['/http/apps/scss/css', 'scss', '', '/http', '/apps/scss/css'], + ['/srv/apps2/scss/css', 'scss', '', '/http', '/apps2/scss/css'], + // Sub directory install + ['/http/nextcloud/core/css', 'core', '/nextcloud', '/http/nextcloud', '/nextcloud/core/css'], + ['/http/nextcloud/apps/scss/css', 'scss', '/nextcloud', '/http/nextcloud', '/nextcloud/apps/scss/css'], + ['/srv/apps2/scss/css', 'scss', '/nextcloud', '/http/nextcloud', '/apps2/scss/css'] + ]; + } + /** * @param $path * @param $appName diff --git a/tests/lib/UrlGeneratorTest.php b/tests/lib/UrlGeneratorTest.php index 69067f51e081c..340c9c7082d21 100644 --- a/tests/lib/UrlGeneratorTest.php +++ b/tests/lib/UrlGeneratorTest.php @@ -27,6 +27,8 @@ class UrlGeneratorTest extends \Test\TestCase { private $request; /** @var IURLGenerator */ private $urlGenerator; + /** @var string */ + private $originalWebRoot; public function setUp() { parent::setUp(); @@ -38,6 +40,12 @@ public function setUp() { $this->cacheFactory, $this->request ); + $this->originalWebRoot = \OC::$WEBROOT; + } + + public function tearDown() { + // Reset webRoot + \OC::$WEBROOT = $this->originalWebRoot; } private function mockBaseUrl() { @@ -47,7 +55,6 @@ private function mockBaseUrl() { $this->request->expects($this->once()) ->method('getServerHost') ->willReturn('localhost'); - } /** @@ -156,4 +163,3 @@ public function testGetBaseUrl() { } } - From 51cc76b80db415320c8e34cbc961855fac77b77c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?John=20Molakvo=C3=A6=20=28skjnldsv=29?= Date: Thu, 4 Jan 2018 08:35:38 +0100 Subject: [PATCH 09/15] Fixed tests MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: John Molakvoæ (skjnldsv) --- tests/lib/Template/CSSResourceLocatorTest.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/lib/Template/CSSResourceLocatorTest.php b/tests/lib/Template/CSSResourceLocatorTest.php index ee209a599d64a..c3d2a4434b92a 100644 --- a/tests/lib/Template/CSSResourceLocatorTest.php +++ b/tests/lib/Template/CSSResourceLocatorTest.php @@ -204,7 +204,7 @@ public function testFindSCSSWithAppPathSymlink() { $webRoot = $resource[1]; $file = $resource[2]; - $expectedRoot = '/'; + $expectedRoot = ''; $expectedWebRoot = ''; $expectedFile = 'test-file'; From fa95733b0d23490d5ca6c4611e0d5c06f18e5fe5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?John=20Molakvo=C3=A6=20=28skjnldsv=29?= Date: Thu, 4 Jan 2018 13:24:21 +0100 Subject: [PATCH 10/15] Fixed url rebase with theming MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: John Molakvoæ (skjnldsv) --- lib/private/Template/SCSSCacher.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/private/Template/SCSSCacher.php b/lib/private/Template/SCSSCacher.php index 542ca1688f556..b091e555c1260 100644 --- a/lib/private/Template/SCSSCacher.php +++ b/lib/private/Template/SCSSCacher.php @@ -282,7 +282,7 @@ private function getInjectedVariables() { */ private function rebaseUrls($css, $webDir) { $re = '/url\([\'"]([\.\w?=\/-]*)[\'"]\)/x'; - $subst = 'url(\''.$webDir.'/$1\')'; + $subst = 'url('.$webDir.'/$1)'; return preg_replace($re, $subst, $css); } From cf53560218281571d686fc280a5b47c43330d6e9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?John=20Molakvo=C3=A6=20=28skjnldsv=29?= Date: Thu, 4 Jan 2018 19:10:27 +0100 Subject: [PATCH 11/15] Proberly detect variable changes MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: John Molakvoæ (skjnldsv) --- lib/private/Template/SCSSCacher.php | 3 +++ 1 file changed, 3 insertions(+) diff --git a/lib/private/Template/SCSSCacher.php b/lib/private/Template/SCSSCacher.php index b091e555c1260..60b3c475f65fa 100644 --- a/lib/private/Template/SCSSCacher.php +++ b/lib/private/Template/SCSSCacher.php @@ -135,6 +135,9 @@ public function getCachedCSS($appName, $fileName) { * @return boolean */ private function isCached($fileNameCSS, ISimpleFolder $folder) { + if ($this->variablesChanged()) { + return false; + } try { $cachedFile = $folder->getFile($fileNameCSS); if ($cachedFile->getSize() > 0) { From 1f2437e2c5add2fc49e1b32c589b478867a6a843 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?John=20Molakvo=C3=A6=20=28skjnldsv=29?= Date: Thu, 4 Jan 2018 19:11:38 +0100 Subject: [PATCH 12/15] Fixup! Proberly detect variable changes MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: John Molakvoæ (skjnldsv) --- lib/private/Template/SCSSCacher.php | 4 ---- 1 file changed, 4 deletions(-) diff --git a/lib/private/Template/SCSSCacher.php b/lib/private/Template/SCSSCacher.php index 60b3c475f65fa..e27f5aed857f5 100644 --- a/lib/private/Template/SCSSCacher.php +++ b/lib/private/Template/SCSSCacher.php @@ -111,10 +111,6 @@ public function process($root, $file, $app) { $folder = $this->appData->newFolder($app); } - - if(!$this->variablesChanged() && $this->isCached($fileNameCSS, $folder)) { - return true; - } return $this->cache($path, $fileNameCSS, $fileNameSCSS, $folder, $webDir); } From 7bc63f6135f6f6dfdd418757d446ca810dfd5abf Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Julius=20H=C3=A4rtl?= Date: Fri, 5 Jan 2018 08:15:42 +0100 Subject: [PATCH 13/15] Fix faulty path in theming scss generation MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Julius Härtl --- apps/theming/lib/Controller/ThemingController.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/apps/theming/lib/Controller/ThemingController.php b/apps/theming/lib/Controller/ThemingController.php index b409d309f4d4a..f8926661c226a 100644 --- a/apps/theming/lib/Controller/ThemingController.php +++ b/apps/theming/lib/Controller/ThemingController.php @@ -171,7 +171,7 @@ public function updateStylesheet($setting, $value) { $this->themingDefaults->set($setting, $value); // reprocess server scss for preview - $cssCached = $this->scssCacher->process(\OC::$SERVERROOT, '/core/css/server.scss', 'core'); + $cssCached = $this->scssCacher->process(\OC::$SERVERROOT, 'core/css/server.scss', 'core'); return new DataResponse( [ From 7a282dee89d1b3036b7712911231dc71c06eaa55 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?John=20Molakvo=C3=A6=20=28skjnldsv=29?= Date: Fri, 5 Jan 2018 08:34:32 +0100 Subject: [PATCH 14/15] Rollback caching fix MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: John Molakvoæ (skjnldsv) --- lib/private/Template/SCSSCacher.php | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/lib/private/Template/SCSSCacher.php b/lib/private/Template/SCSSCacher.php index e27f5aed857f5..09c7f604273c5 100644 --- a/lib/private/Template/SCSSCacher.php +++ b/lib/private/Template/SCSSCacher.php @@ -111,6 +111,10 @@ public function process($root, $file, $app) { $folder = $this->appData->newFolder($app); } + if(!$this->variablesChanged() && $this->isCached($fileNameCSS, $folder)) { + return true; + } + return $this->cache($path, $fileNameCSS, $fileNameSCSS, $folder, $webDir); } @@ -131,9 +135,6 @@ public function getCachedCSS($appName, $fileName) { * @return boolean */ private function isCached($fileNameCSS, ISimpleFolder $folder) { - if ($this->variablesChanged()) { - return false; - } try { $cachedFile = $folder->getFile($fileNameCSS); if ($cachedFile->getSize() > 0) { From b95d18b85e21e5a19ff0511cf4a37cf9f229eaa5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?John=20Molakvo=C3=A6=20=28skjnldsv=29?= Date: Fri, 5 Jan 2018 08:35:38 +0100 Subject: [PATCH 15/15] Revert rebaseurl function edit MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: John Molakvoæ (skjnldsv) --- lib/private/Template/SCSSCacher.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/private/Template/SCSSCacher.php b/lib/private/Template/SCSSCacher.php index 09c7f604273c5..0b85af3f27f31 100644 --- a/lib/private/Template/SCSSCacher.php +++ b/lib/private/Template/SCSSCacher.php @@ -282,7 +282,7 @@ private function getInjectedVariables() { */ private function rebaseUrls($css, $webDir) { $re = '/url\([\'"]([\.\w?=\/-]*)[\'"]\)/x'; - $subst = 'url('.$webDir.'/$1)'; + $subst = 'url(\''.$webDir.'/$1\')'; return preg_replace($re, $subst, $css); }