From 5fbba7854b433e8b77ecb09edf0b804c233ae2aa Mon Sep 17 00:00:00 2001 From: Robin Appelman Date: Thu, 12 Apr 2018 12:28:25 +0200 Subject: [PATCH] fix appinfo parsing when a single localized option is provided Signed-off-by: Robin Appelman --- lib/private/legacy/app.php | 5 +++++ tests/data/app/description-multi-lang.xml | 8 ++++++++ tests/data/app/description-single-lang.xml | 7 +++++++ tests/lib/AppTest.php | 14 ++++++++++++++ 4 files changed, 34 insertions(+) create mode 100644 tests/data/app/description-multi-lang.xml create mode 100644 tests/data/app/description-single-lang.xml diff --git a/lib/private/legacy/app.php b/lib/private/legacy/app.php index 02d5f6fea4..eab064962b 100644 --- a/lib/private/legacy/app.php +++ b/lib/private/legacy/app.php @@ -1157,6 +1157,11 @@ class OC_App { } protected static function findBestL10NOption($options, $lang) { + // only a single option + if (isset($options['@value'])) { + return $options['@value']; + } + $fallback = $similarLangFallback = $englishFallback = false; $lang = strtolower($lang); diff --git a/tests/data/app/description-multi-lang.xml b/tests/data/app/description-multi-lang.xml new file mode 100644 index 0000000000..e7eee3bcb8 --- /dev/null +++ b/tests/data/app/description-multi-lang.xml @@ -0,0 +1,8 @@ + + + files_encryption + Server-side Encryption + English + German + AGPL + diff --git a/tests/data/app/description-single-lang.xml b/tests/data/app/description-single-lang.xml new file mode 100644 index 0000000000..5fb1ba07e8 --- /dev/null +++ b/tests/data/app/description-single-lang.xml @@ -0,0 +1,7 @@ + + + files_encryption + Server-side Encryption + English + AGPL + diff --git a/tests/lib/AppTest.php b/tests/lib/AppTest.php index 620e9344c4..03e7a70f7b 100644 --- a/tests/lib/AppTest.php +++ b/tests/lib/AppTest.php @@ -9,6 +9,7 @@ namespace Test; +use OC\App\InfoParser; use OC\AppConfig; use OCP\IAppConfig; @@ -605,5 +606,18 @@ class AppTest extends \Test\TestCase { public function testParseAppInfo(array $data, array $expected) { $this->assertSame($expected, \OC_App::parseAppInfo($data)); } + + public function testParseAppInfoL10N() { + $parser = new InfoParser(); + $data = $parser->parse(\OC::$SERVERROOT. "/tests/data/app/description-multi-lang.xml"); + $this->assertEquals('English', \OC_App::parseAppInfo($data, 'en')['description']); + $this->assertEquals('German', \OC_App::parseAppInfo($data, 'de')['description']); + } + + public function testParseAppInfoL10NSingleLanguage() { + $parser = new InfoParser(); + $data = $parser->parse(\OC::$SERVERROOT. "/tests/data/app/description-single-lang.xml"); + $this->assertEquals('English', \OC_App::parseAppInfo($data, 'en')['description']); + } }