diff options
author | Morris Jobke <hey@morrisjobke.de> | 2015-01-13 14:48:30 +0100 |
---|---|---|
committer | Morris Jobke <hey@morrisjobke.de> | 2015-01-14 13:58:31 +0100 |
commit | 520d8ec53b672e768e59eaf0409559bbecc6c042 (patch) | |
tree | ce2071bc2315cfbd160fa4d3e9347bd1ee21471d | |
parent | ba8c050d2b827804d0c860be19591c9d35fd0adf (diff) | |
download | nextcloud-server-520d8ec53b672e768e59eaf0409559bbecc6c042.tar.gz nextcloud-server-520d8ec53b672e768e59eaf0409559bbecc6c042.zip |
OC_App::parseAppInfo
* replace line breaks (on non empty lines) in the app description by spaces
* fixes #13315
* includes unit tests
-rw-r--r-- | lib/private/app.php | 39 | ||||
-rw-r--r-- | tests/lib/app.php | 29 |
2 files changed, 67 insertions, 1 deletions
diff --git a/lib/private/app.php b/lib/private/app.php index ecdc8ca8320..94a1f273bb5 100644 --- a/lib/private/app.php +++ b/lib/private/app.php @@ -641,6 +641,10 @@ class OC_App { $parser = new \OC\App\InfoParser(\OC::$server->getHTTPHelper(), \OC::$server->getURLGenerator()); $data = $parser->parse($file); + if(is_array($data)) { + $data = OC_App::parseAppInfo($data); + } + self::$appInfo[$appId] = $data; return $data; @@ -913,7 +917,8 @@ class OC_App { $i = 0; $l = \OC::$server->getL10N('core'); foreach ($remoteApps as $app) { - $app1[$i] = $app; + // enhance app info (for example the description) + $app1[$i] = OC_App::parseAppInfo($app); $app1[$i]['author'] = $app['personid']; $app1[$i]['ocs_id'] = $app['id']; $app1[$i]['internal'] = $app1[$i]['active'] = 0; @@ -1194,4 +1199,36 @@ class OC_App { return false; } } + + /** + * parses the app data array and enhanced the 'description' value + * + * @param array $data the app data + * @return array improved app data + */ + public static function parseAppInfo(array $data) { + + // just modify the description if it is available + // otherwise this will create a $data element with an empty 'description' + if(isset($data['description'])) { + // sometimes the description contains line breaks and they are then also + // shown in this way in the app management which isn't wanted as HTML + // manages line breaks itself + + // first of all we split on empty lines + $paragraphs = preg_split("!\n[[:space:]]*\n!m", $data['description']); + + $result = []; + foreach ($paragraphs as $value) { + // replace multiple whitespace (tabs, space, newlines) inside a paragraph + // with a single space - also trims whitespace + $result[] = trim(preg_replace('![[:space:]]+!m', ' ', $value)); + } + + // join the single paragraphs with a empty line in between + $data['description'] = implode("\n\n", $result); + } + + return $data; + } } diff --git a/tests/lib/app.php b/tests/lib/app.php index 23c1a340e03..529de82e670 100644 --- a/tests/lib/app.php +++ b/tests/lib/app.php @@ -459,5 +459,34 @@ class Test_App extends \Test\TestCase { // Remove the cache of the mocked apps list with a forceRefresh \OC_App::getEnabledApps(true); } + + /** + * Providers for the app data values + */ + function appDataProvider() { + return [ + [ + ['description' => " \t This is a multiline \n test with \n \t \n \n some new lines "], + ['description' => "This is a multiline test with\n\nsome new lines"] + ], + [ + ['description' => " \t This is a multiline \n test with \n \t some new lines "], + ['description' => "This is a multiline test with some new lines"] + ], + [ + ['not-a-description' => " \t This is a multiline \n test with \n \t some new lines "], + ['not-a-description' => " \t This is a multiline \n test with \n \t some new lines "] + ], + ]; + } + + /** + * Test app info parser + * + * @dataProvider appDataProvider + */ + public function testParseAppInfo($data, $expected) { + $this->assertEquals($expected, \OC_App::parseAppInfo($data)); + } } |