diff --git a/lib/private/Template/JSResourceLocator.php b/lib/private/Template/JSResourceLocator.php index 0f25b033776e..17dec075ccc6 100644 --- a/lib/private/Template/JSResourceLocator.php +++ b/lib/private/Template/JSResourceLocator.php @@ -52,13 +52,20 @@ public function doFind($script) { if ($found) { return; } - } elseif ($this->appendOnceIfExist($baseDirectory, $themeDirectory.'/apps/'.$fullScript, $webRoot) - || $this->appendOnceIfExist($baseDirectory, $themeDirectory.'/'.$fullScript, $webRoot) - || $this->appendOnceIfExist($this->serverroot, $fullScript) - || $this->appendOnceIfExist($baseDirectory, $themeDirectory.'/core/'.$fullScript, $webRoot) - || $this->appendOnceIfExist($this->serverroot, 'core/'.$fullScript) - ) { - return; + } else { + // Search in an active theme first. But only if it is active + if ( + $themeDirectory !== '' && $this->appendOnceIfExist($baseDirectory, $themeDirectory.'/apps/'.$fullScript, $webRoot) + ) { + return; + } + if ($this->appendOnceIfExist($baseDirectory, $themeDirectory.'/'.$fullScript, $webRoot) + || $this->appendOnceIfExist($this->serverroot, $fullScript) + || $this->appendOnceIfExist($baseDirectory, $themeDirectory.'/core/'.$fullScript, $webRoot) + || $this->appendOnceIfExist($this->serverroot, 'core/'.$fullScript) + ) { + return; + } } $app = \substr($fullScript, 0, \strpos($fullScript, '/')); diff --git a/tests/lib/Template/JSResourceLocatorTest.php b/tests/lib/Template/JSResourceLocatorTest.php index c3fa93c80fc5..052a8778dd5e 100644 --- a/tests/lib/Template/JSResourceLocatorTest.php +++ b/tests/lib/Template/JSResourceLocatorTest.php @@ -101,6 +101,32 @@ public function testFindAppScript() { $locator->find(['randomapp/js/script']); } + public function testFindAppScriptWithNoThemeActive() { + $this->themeAppDir = ''; + /** @var \OC\Template\JSResourceLocator $locator */ + $locator = $this->getResourceLocator( + '', + [$this->serverRoot => 'map'], + ['foo' => 'bar'] + ); + $this->appManager->expects($this->any()) + ->method('getAppPath') + ->with('randomapp') + ->willReturn('/var/www/apps-external/randomapp'); + + $locator->expects($this->exactly(5)) + ->method('appendOnceIfExist') + ->withConsecutive( + ['/var/www/apps', '/randomapp/js/script.js', ''], + ['/var/www/owncloud', 'randomapp/js/script.js', ''], + ['/var/www/apps', '/core/randomapp/js/script.js', ''], + ['/var/www/owncloud', 'core/randomapp/js/script.js', ''], + ['/var/www/apps-external/randomapp', 'js/script.js', ''] + ); + + $locator->find(['randomapp/js/script']); + } + public function testFindL10nScript() { /** @var \OC\Template\JSResourceLocator $locator */ $locator = $this->getResourceLocator(