From c636872c907b56e01713ca03870083437f85191e Mon Sep 17 00:00:00 2001 From: Vladimir Ischenko Date: Fri, 20 Nov 2026 12:46:35 +0300 Subject: [PATCH] fix: preserve the default name for localized ExApps Converting info.xml to an array turns repeated name elements into an array. Resolve the default XML name before AppAPI saves it and creates the container environment. Assisted-by: Codex:gpt-6 Signed-off-by: Vladimir Ischenko --- lib/Service/ExAppService.php | 4 ++++ .../Service/ExAppServiceGetAppInfoTest.php | 20 ++++++++++++++++++- 2 files changed, 23 insertions(+), 1 deletion(-) diff --git a/lib/Service/ExAppService.php b/lib/Service/ExAppService.php index a77c3719..3cd83b2b 100644 --- a/lib/Service/ExAppService.php +++ b/lib/Service/ExAppService.php @@ -284,6 +284,10 @@ public function getAppInfo(string $appId, ?string $infoXml, ?string $jsonInfo, ? } } $appInfo = json_decode(json_encode((array)$xmlAppInfo), true); + if (is_array($appInfo['name'] ?? null)) { + $defaultNames = $xmlAppInfo->xpath('name[not(@lang) or @lang="en"]'); + $appInfo['name'] = (string)($defaultNames[0] ?? $xmlAppInfo->name); + } if (isset($appInfo['external-app']['routes']['route'])) { if (isset($appInfo['external-app']['routes']['route'][0])) { $appInfo['external-app']['routes'] = $appInfo['external-app']['routes']['route']; diff --git a/tests/php/Service/ExAppServiceGetAppInfoTest.php b/tests/php/Service/ExAppServiceGetAppInfoTest.php index 8e052df8..c59653a2 100644 --- a/tests/php/Service/ExAppServiceGetAppInfoTest.php +++ b/tests/php/Service/ExAppServiceGetAppInfoTest.php @@ -27,6 +27,7 @@ use OCP\ICacheFactory; use OCP\IConfig; use OCP\IUserManager; +use PHPUnit\Framework\Attributes\DataProvider; use PHPUnit\Framework\TestCase; use Psr\Log\LoggerInterface; @@ -75,12 +76,13 @@ protected function tearDown(): void { parent::tearDown(); } - private function writeInfoXml(string $environmentVariables): string { + private function writeInfoXml(string $environmentVariables, string $names = ''): string { $this->infoXmlPath = tempnam(sys_get_temp_dir(), 'appapi-test-info-'); file_put_contents($this->infoXmlPath, << test_app +$names $environmentVariables @@ -91,6 +93,22 @@ private function writeInfoXml(string $environmentVariables): string { return $this->infoXmlPath; } + #[DataProvider('defaultNameElements')] + public function testLocalizedNamesUseTheDefaultFromInfoXml(string $defaultNameElement): void { + $infoXml = $this->writeInfoXml('', 'Deutscher Name' . $defaultNameElement); + + $appInfo = $this->service->getAppInfo('test_app', $infoXml, null); + + self::assertSame('Default Name', $appInfo['name']); + } + + public static function defaultNameElements(): array { + return [ + 'without language' => ['Default Name'], + 'explicit English' => ['Default Name'], + ]; + } + public function testEmptyDefaultElementIsDroppedFromInfoXml(): void { $infoXml = $this->writeInfoXml(<<