Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions changelog/unreleased/40607
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
Bugfix: Use correct themed l10n app folder when app lives outside of server root

When an app_path is pointing outside of the ownCloud server root or uses an
symlink under certain conditions the l10n folder points to an invalid location
and results in a crash of the server. This happened due to the assumption that
app paths always start with the server root path.

https://github.com/owncloud/core/pull/40607
31 changes: 19 additions & 12 deletions lib/private/L10N/Factory.php
Original file line number Diff line number Diff line change
Expand Up @@ -52,11 +52,6 @@ class Factory implements IFactory {
*/
protected $availableLanguages = [];

/**
* @var array Structure: string => callable
*/
protected $pluralFunctions = [];

/** @var IConfig */
protected $config;

Expand All @@ -76,7 +71,7 @@ class Factory implements IFactory {
* @param IConfig $config
* @param IRequest $request
* @param IThemeService $themeService
* @param IUserSession $userSession
* @param IUserSession|null $userSession
* @param string $serverRoot
*/
public function __construct(
Expand Down Expand Up @@ -194,10 +189,9 @@ public function findAvailableLanguages($app = null) {
$available = \array_merge($available, $this->findAvailableLanguageFiles($dir));

// merge with translations from themes
$relativePath = \substr($dir, \strlen($this->serverRoot));
$themeDir = $this->getActiveThemeDirectory();
if ($themeDir !== '') {
$themeDir .= $relativePath;
$themeDir = $this->findL10nDirInTheme($themeDir, $app);
$available = \array_merge($available, $this->findAvailableLanguageFiles($themeDir));
}

Expand Down Expand Up @@ -290,10 +284,9 @@ public function getL10nFilesForApp($app, $lang) {
}

// merge with translations from themes
$relativePath = \substr($transFile, \strlen($this->serverRoot));
$themeDir = $this->getActiveThemeDirectory();
if ($themeDir !== '') {
$themeTransFile = $themeDir . $relativePath;
$themeTransFile = $this->findL10nDirInTheme($themeDir, $app) . "/$lang.json";
if (\file_exists($themeTransFile)) {
$languageFiles[] = $themeTransFile;
}
Expand All @@ -305,10 +298,10 @@ public function getL10nFilesForApp($app, $lang) {
/**
* find the l10n directory
*
* @param string $app App id or empty string for core
* @param string|null $app App id or empty string for core
* @return string directory
*/
protected function findL10nDir($app = null) {
protected function findL10nDir($app): string {
if (\in_array($app, ['core', 'lib', 'settings'])) {
if (\file_exists($this->serverRoot . '/' . $app . '/l10n/')) {
return $this->serverRoot . '/' . $app . '/l10n/';
Expand All @@ -320,6 +313,20 @@ protected function findL10nDir($app = null) {
return $this->serverRoot . '/core/l10n/';
}

protected function findL10nDirInTheme(string $themeDir, $app): string {
if ($app) {
if (\in_array($app, ['core', 'lib', 'settings'])) {
$p = $themeDir . '/' . $app . '/l10n/';
} else {
$p = $themeDir . '/apps/' . $app . '/l10n/';
}
if (\file_exists($p)) {
return $p;
}
}
return $themeDir . '/core/l10n/';
}

/**
* @param string $dir
* @return array
Expand Down
Loading