aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorFerdinand Thiessen <opensource@fthiessen.de>2023-05-11 17:51:55 +0200
committerFerdinand Thiessen <opensource@fthiessen.de>2023-05-11 18:22:24 +0200
commit31c01fa3da094897d2bffbbf2bd4848773c62c67 (patch)
tree762abd6ad1e6cf063803fe105518a3679a161bc1
parent9d2d3d482bce004d134dd87d7b37c3dfb6513412 (diff)
downloadnextcloud-server-31c01fa3da094897d2bffbbf2bd4848773c62c67.tar.gz
nextcloud-server-31c01fa3da094897d2bffbbf2bd4848773c62c67.zip
fix(JSResourceLocator): Handle missing translations silently
Signed-off-by: Ferdinand Thiessen <opensource@fthiessen.de>
-rw-r--r--lib/private/Template/JSResourceLocator.php25
-rw-r--r--tests/lib/Template/JSResourceLocatorTest.php22
2 files changed, 38 insertions, 9 deletions
diff --git a/lib/private/Template/JSResourceLocator.php b/lib/private/Template/JSResourceLocator.php
index 120234146e1..61611c69b0f 100644
--- a/lib/private/Template/JSResourceLocator.php
+++ b/lib/private/Template/JSResourceLocator.php
@@ -99,21 +99,28 @@ class JSResourceLocator extends ResourceLocator {
// gets turned into cwd.
$app_path = realpath($app_path);
- // missing translations files will be ignored
- if (strpos($script, 'l10n/') === 0) {
- $this->appendScriptIfExist($app_path, $script, $app_url);
+ // check combined files
+ if ($this->cacheAndAppendCombineJsonIfExist($app_path, $script.'.json', $app)) {
return;
}
- if (!$this->cacheAndAppendCombineJsonIfExist($app_path, $script.'.json', $app)) {
- $this->appendScriptIfExist($app_path, $script, $app_url);
+ // fallback to plain file location
+ if ($this->appendScriptIfExist($app_path, $script, $app_url)) {
+ return;
}
} catch (AppPathNotFoundException) {
- $this->logger->error('Could not find resource {resource} to load', [
- 'resource' => $app . '/' . $script . '.js',
- 'app' => 'jsresourceloader',
- ]);
+ // pass (general error handling happens below)
}
+
+ // missing translations files will be ignored
+ if (strpos($script, 'l10n/') === 0) {
+ return;
+ }
+
+ $this->logger->error('Could not find resource {resource} to load', [
+ 'resource' => $app . '/' . $script . '.js',
+ 'app' => 'jsresourceloader',
+ ]);
}
/**
diff --git a/tests/lib/Template/JSResourceLocatorTest.php b/tests/lib/Template/JSResourceLocatorTest.php
index 9ac6a32e22c..f5af138060a 100644
--- a/tests/lib/Template/JSResourceLocatorTest.php
+++ b/tests/lib/Template/JSResourceLocatorTest.php
@@ -26,6 +26,7 @@ namespace Test\Template;
use OC\SystemConfig;
use OC\Template\JSCombiner;
use OC\Template\JSResourceLocator;
+use OCP\App\AppPathNotFoundException;
use OCP\App\IAppManager;
use OCP\Files\IAppData;
use OCP\ICacheFactory;
@@ -139,6 +140,27 @@ class JSResourceLocatorTest extends \Test\TestCase {
$this->rrmdir($new_apps_path);
}
+ public function testNotExistingTranslationHandledSilent() {
+ $this->appManager->expects($this->once())
+ ->method('getAppPath')
+ ->with('core')
+ ->willThrowException(new AppPathNotFoundException());
+ $this->appManager->expects($this->once())
+ ->method('getAppWebPath')
+ ->with('core')
+ ->willThrowException(new AppPathNotFoundException());
+ // Assert logger is not called
+ $this->logger->expects($this->never())
+ ->method('error');
+
+ // Run the tests
+ $locator = $this->jsResourceLocator();
+ $locator->find(["core/l10n/en.js"]);
+
+ $resources = $locator->getResources();
+ $this->assertCount(0, $resources);
+ }
+
public function testFindModuleJSWithFallback() {
// First create new apps path, and a symlink to it
$apps_dirname = $this->randomString();