Skip to content

Commit d6df818

Browse files
committed
Fixed webroot for scss files
Fixed tests Signed-off-by: John Molakvoæ (skjnldsv) <skjnldsv@protonmail.com>
1 parent 35d8e7c commit d6df818

File tree

3 files changed

+13
-20
lines changed

3 files changed

+13
-20
lines changed

lib/private/Template/CSSResourceLocator.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,7 @@ protected function cacheAndAppendScssIfExist($root, $file, $app = 'core') {
108108
if($this->scssCacher !== null) {
109109
if($this->scssCacher->process($root, $file, $app)) {
110110

111-
$this->append($root, $this->scssCacher->getCachedSCSS($app, $file), false, true, true);
111+
$this->append($root, $this->scssCacher->getCachedSCSS($app, $file), \OC::$WEBROOT, true, true);
112112
return true;
113113
} else {
114114
$this->logger->warning('Failed to compile and/or save '.$root.'/'.$file, ['app' => 'core']);
@@ -145,7 +145,7 @@ public function append($root, $file, $webRoot = null, $throw = true, $scss = fal
145145
}
146146
}
147147

148-
$this->resources[] = array($webRoot? : '/', $webRoot, $file);
148+
$this->resources[] = array($webRoot? : \OC::$WEBROOT, $webRoot, $file);
149149
}
150150
}
151151
}

lib/private/Template/SCSSCacher.php

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -102,16 +102,19 @@ public function process($root, $file, $app) {
102102
$fileNameCSS = $this->prependBaseurlPrefix(str_replace('.scss', '.css', $fileNameSCSS));
103103

104104
$path = implode('/', $path);
105+
$webDir = null;
105106

106107
// Detect if path is within an app path
107108
$app_paths = $this->config->getSystemValue('apps_paths');
108-
foreach ($app_paths as $app_path) {
109-
if(strpos($path, $app_path["path"]) === 0) {
110-
$webDir = $app_path["url"].str_replace($app_path["path"], '', $path);
111-
break;
109+
if (!empty($app_paths)) {
110+
foreach ($app_paths as $app_path) {
111+
if (strpos($path, $app_path["path"]) === 0) {
112+
$webDir = $app_path["url"].str_replace($app_path["path"], '', $path);
113+
break;
114+
}
112115
}
113116
}
114-
if(is_null($webDir)) {
117+
if (is_null($webDir)) {
115118
$webDir = substr($path, strlen($this->serverRoot));
116119
}
117120

@@ -165,7 +168,7 @@ private function isCached($fileNameCSS, ISimpleFolder $folder) {
165168
}
166169
}
167170
}
168-
return false;
171+
return true;
169172
} catch(NotFoundException $e) {
170173
return false;
171174
}
@@ -304,7 +307,6 @@ private function rebaseUrls($css, $webDir) {
304307
* @return string
305308
*/
306309
public function getCachedSCSS($appName, $fileName) {
307-
//var_dump([$appName, $fileName]);
308310
$tmpfileLoc = explode('/', $fileName);
309311
$fileName = array_pop($tmpfileLoc);
310312
$fileName = $this->prependBaseurlPrefix(str_replace('.scss', '.css', $fileName));

tests/lib/Template/SCSSCacherTest.php

Lines changed: 2 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -352,19 +352,10 @@ public function testCacheFailure() {
352352
}
353353

354354
public function testRebaseUrls() {
355-
$webDir = 'apps/files/css';
355+
$webDir = '/apps/files/css';
356356
$css = '#id { background-image: url(\'../img/image.jpg\'); }';
357357
$actual = self::invokePrivate($this->scssCacher, 'rebaseUrls', [$css, $webDir]);
358-
$expected = '#id { background-image: url(\'../../../apps/files/css/../img/image.jpg\'); }';
359-
$this->assertEquals($expected, $actual);
360-
}
361-
362-
public function testRebaseUrlsIgnoreFrontendController() {
363-
$this->config->expects($this->once())->method('getSystemValue')->with('htaccess.IgnoreFrontController', false)->willReturn(true);
364-
$webDir = 'apps/files/css';
365-
$css = '#id { background-image: url(\'../img/image.jpg\'); }';
366-
$actual = self::invokePrivate($this->scssCacher, 'rebaseUrls', [$css, $webDir]);
367-
$expected = '#id { background-image: url(\'../../apps/files/css/../img/image.jpg\'); }';
358+
$expected = '#id { background-image: url(\'/apps/files/css/../img/image.jpg\'); }';
368359
$this->assertEquals($expected, $actual);
369360
}
370361

0 commit comments

Comments
 (0)