Skip to content

Commit

Permalink
Merge pull request #17297 from owncloud/stable8-use-mb-functions
Browse files Browse the repository at this point in the history
[stable8] Use UTF-8 mode for preg_split and preg_replace
  • Loading branch information
LukasReschke committed Jul 1, 2015
2 parents f8e6800 + 7ec91b9 commit 78dc8ca
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 4 deletions.
5 changes: 3 additions & 2 deletions lib/private/app.php
Original file line number Diff line number Diff line change
Expand Up @@ -1227,17 +1227,18 @@ public static function parseAppInfo(array $data) {
// manages line breaks itself

// first of all we split on empty lines
$paragraphs = preg_split("!\n[[:space:]]*\n!m", $data['description']);
$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:]]+!m', ' ', $value));
$result[] = trim(preg_replace('![[:space:]]+!mu', ' ', $value));
}

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

}

return $data;
Expand Down
10 changes: 8 additions & 2 deletions tests/lib/app.php
Original file line number Diff line number Diff line change
Expand Up @@ -522,6 +522,10 @@ function appDataProvider() {
['description' => " \t This is a multiline \n test with \n \t some new lines "],
['description' => "This is a multiline test with some new lines"]
],
[
['description' => hex2bin('5065726d657420646520732761757468656e7469666965722064616e732070697769676f20646972656374656d656e74206176656320736573206964656e74696669616e7473206f776e636c6f75642073616e73206c65732072657461706572206574206d657420c3a0206a6f757273206365757820636920656e20636173206465206368616e67656d656e74206465206d6f742064652070617373652e0d0a0d')],
['description' => "Permet de s'authentifier dans piwigo directement avec ses identifiants owncloud sans les retaper et met à jours ceux ci en cas de changement de mot de passe."]
],
[
['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 "]
Expand All @@ -533,9 +537,11 @@ function appDataProvider() {
* Test app info parser
*
* @dataProvider appDataProvider
* @param array $data
* @param array $expected
*/
public function testParseAppInfo($data, $expected) {
$this->assertEquals($expected, \OC_App::parseAppInfo($data));
public function testParseAppInfo(array $data, array $expected) {
$this->assertSame($expected, \OC_App::parseAppInfo($data));
}
}

0 comments on commit 78dc8ca

Please sign in to comment.