Commit a9685a92 authored by alexpott's avatar alexpott

Issue #1712106 by jamix, dawehner, m4olivei, Boobaa, InternetDevels,...

Issue #1712106 by jamix, dawehner, m4olivei, Boobaa, InternetDevels, JacobSanford: truncate_utf8() cuts on the first newline character when $wordsafe == TRUE
parent 9788b225
......@@ -548,7 +548,7 @@ public static function truncate($string, $max_length, $wordsafe = FALSE, $add_el
// Find the last word boundary, if there is one within $min_wordsafe_length
// to $max_length characters. preg_match() is always greedy, so it will
// find the longest string possible.
$found = preg_match('/^(.{' . $min_wordsafe_length . ',' . $max_length . '})[' . Unicode::PREG_CLASS_WORD_BOUNDARY . ']/u', $string, $matches);
$found = preg_match('/^(.{' . $min_wordsafe_length . ',' . $max_length . '})[' . Unicode::PREG_CLASS_WORD_BOUNDARY . ']/us', $string, $matches);
if ($found) {
$string = $matches[1];
}
......
......@@ -376,7 +376,7 @@ public function testTruncate($text, $max_length, $expected, $wordsafe = FALSE, $
* - (optional) Boolean for the $add_ellipsis flag. Defaults to FALSE.
*/
public function providerTruncate() {
return [
$tests = [
['frànçAIS is über-åwesome', 24, 'frànçAIS is über-åwesome'],
['frànçAIS is über-åwesome', 23, 'frànçAIS is über-åwesom'],
['frànçAIS is über-åwesome', 17, 'frànçAIS is über-'],
......@@ -422,6 +422,24 @@ public function providerTruncate() {
['Help! Help! Help!', 3, 'He…', TRUE, TRUE],
['Help! Help! Help!', 2, 'H…', TRUE, TRUE],
];
// Test truncate on text with muliplte lines.
$multi_line = <<<EOF
This is a text that spans multiple lines.
Line 2 goes here.
EOF;
$multi_line_wordsafe = <<<EOF
This is a text that spans multiple lines.
Line 2
EOF;
$multi_line_non_wordsafe = <<<EOF
This is a text that spans multiple lines.
Line 2 go
EOF;
$tests[] = [$multi_line, 51, $multi_line_wordsafe, TRUE];
$tests[] = [$multi_line, 51, $multi_line_non_wordsafe, FALSE];
return $tests;
}
/**
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment