Skip to content

Commit

Permalink
Only do the description kung-fu on strings - fixes #17028
Browse files Browse the repository at this point in the history
  • Loading branch information
DeepDiver1975 authored and MorrisJobke committed Jul 2, 2015
1 parent caa3210 commit 2727d97
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 15 deletions.
34 changes: 19 additions & 15 deletions lib/private/app.php
Original file line number Diff line number Diff line change
Expand Up @@ -1223,23 +1223,27 @@ 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!mu", $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:]]+!mu', ' ', $value));
}
if (is_string($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!mu", $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:]]+!mu', ' ', $value));
}

// join the single paragraphs with a empty line in between
$data['description'] = implode("\n\n", $result);
// join the single paragraphs with a empty line in between
$data['description'] = implode("\n\n", $result);

} else {
$data['description'] = '';
}
}

return $data;
Expand Down
4 changes: 4 additions & 0 deletions tests/lib/app.php
Original file line number Diff line number Diff line change
Expand Up @@ -510,6 +510,10 @@ function appDataProvider() {
['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 "]
],
[
['description' => [100, 'bla']],
['description' => ""]
],
];
}

Expand Down

0 comments on commit 2727d97

Please sign in to comment.