Skip to content

Commit

Permalink
Merge pull request #38207 from nextcloud/fix/jsresourcelocator-l10n-h…
Browse files Browse the repository at this point in the history
…andling
  • Loading branch information
skjnldsv authored May 12, 2023
2 parents 0d3df2c + 31c01fa commit 174c226
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 9 deletions.
25 changes: 16 additions & 9 deletions lib/private/Template/JSResourceLocator.php
Original file line number Diff line number Diff line change
Expand Up @@ -99,21 +99,28 @@ public function doFind($script) {
// 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',
]);
}

/**
Expand Down
22 changes: 22 additions & 0 deletions tests/lib/Template/JSResourceLocatorTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
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;
Expand Down Expand Up @@ -139,6 +140,27 @@ public function testFindWithAppPathSymlink() {
$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();
Expand Down

0 comments on commit 174c226

Please sign in to comment.