X Tutup
Skip to content

Commit 1141ca2

Browse files
committed
fix: use correct l10n folder when theme is enabled and apps_path is a symlink
1 parent 954892e commit 1141ca2

File tree

3 files changed

+116
-76
lines changed

3 files changed

+116
-76
lines changed

changelog/unreleased/40607

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
Bugfix: Use correct themed l10n app folder when app lives outside of server root
2+
3+
When an app_path is pointing outside of the ownCloud server root or uses an
4+
symlink under certain conditions the l10n folder points to an invalid location
5+
and results in a crash of the server. This happened due to the assumption that
6+
app paths always start with the server root path.
7+
8+
https://github.com/owncloud/core/pull/40607

lib/private/L10N/Factory.php

Lines changed: 19 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -52,11 +52,6 @@ class Factory implements IFactory {
5252
*/
5353
protected $availableLanguages = [];
5454

55-
/**
56-
* @var array Structure: string => callable
57-
*/
58-
protected $pluralFunctions = [];
59-
6055
/** @var IConfig */
6156
protected $config;
6257

@@ -76,7 +71,7 @@ class Factory implements IFactory {
7671
* @param IConfig $config
7772
* @param IRequest $request
7873
* @param IThemeService $themeService
79-
* @param IUserSession $userSession
74+
* @param IUserSession|null $userSession
8075
* @param string $serverRoot
8176
*/
8277
public function __construct(
@@ -194,10 +189,9 @@ public function findAvailableLanguages($app = null) {
194189
$available = \array_merge($available, $this->findAvailableLanguageFiles($dir));
195190

196191
// merge with translations from themes
197-
$relativePath = \substr($dir, \strlen($this->serverRoot));
198192
$themeDir = $this->getActiveThemeDirectory();
199193
if ($themeDir !== '') {
200-
$themeDir .= $relativePath;
194+
$themeDir = $this->findL10nDirInTheme($themeDir, $app);
201195
$available = \array_merge($available, $this->findAvailableLanguageFiles($themeDir));
202196
}
203197

@@ -290,10 +284,9 @@ public function getL10nFilesForApp($app, $lang) {
290284
}
291285

292286
// merge with translations from themes
293-
$relativePath = \substr($transFile, \strlen($this->serverRoot));
294287
$themeDir = $this->getActiveThemeDirectory();
295288
if ($themeDir !== '') {
296-
$themeTransFile = $themeDir . $relativePath;
289+
$themeTransFile = $this->findL10nDirInTheme($themeDir, $app) . "/$lang.json";
297290
if (\file_exists($themeTransFile)) {
298291
$languageFiles[] = $themeTransFile;
299292
}
@@ -305,10 +298,10 @@ public function getL10nFilesForApp($app, $lang) {
305298
/**
306299
* find the l10n directory
307300
*
308-
* @param string $app App id or empty string for core
301+
* @param string|null $app App id or empty string for core
309302
* @return string directory
310303
*/
311-
protected function findL10nDir($app = null) {
304+
protected function findL10nDir($app): string {
312305
if (\in_array($app, ['core', 'lib', 'settings'])) {
313306
if (\file_exists($this->serverRoot . '/' . $app . '/l10n/')) {
314307
return $this->serverRoot . '/' . $app . '/l10n/';
@@ -320,6 +313,20 @@ protected function findL10nDir($app = null) {
320313
return $this->serverRoot . '/core/l10n/';
321314
}
322315

316+
protected function findL10nDirInTheme(string $themeDir, $app): string {
317+
if ($app) {
318+
if (\in_array($app, ['core', 'lib', 'settings'])) {
319+
$p = $themeDir . '/' . $app . '/l10n/';
320+
} else {
321+
$p = $themeDir . '/apps/' . $app . '/l10n/';
322+
}
323+
if (\file_exists($p)) {
324+
return $p;
325+
}
326+
}
327+
return $themeDir . '/core/l10n/';
328+
}
329+
323330
/**
324331
* @param string $dir
325332
* @return array

0 commit comments

Comments
 (0)
X Tutup