summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAlex Pott2018-01-29 10:13:26 (GMT)
committerAlex Pott2018-01-29 10:14:00 (GMT)
commita9685a928d5cb6d9fbde730ae14b0da021e2e2be (patch)
tree92ace5d26f9e5f9036578ee7d9484ff206c1350a
parent9788b22566be16e709438c89f785ce5bf286910b (diff)
Issue #1712106 by jamix, dawehner, m4olivei, Boobaa, InternetDevels, JacobSanford: truncate_utf8() cuts on the first newline character when $wordsafe == TRUE
-rw-r--r--core/lib/Drupal/Component/Utility/Unicode.php2
-rw-r--r--core/tests/Drupal/Tests/Component/Utility/UnicodeTest.php20
2 files changed, 20 insertions, 2 deletions
diff --git a/core/lib/Drupal/Component/Utility/Unicode.php b/core/lib/Drupal/Component/Utility/Unicode.php
index f8e026f..e136a89 100644
--- a/core/lib/Drupal/Component/Utility/Unicode.php
+++ b/core/lib/Drupal/Component/Utility/Unicode.php
@@ -548,7 +548,7 @@ EOD;
// 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];
}
diff --git a/core/tests/Drupal/Tests/Component/Utility/UnicodeTest.php b/core/tests/Drupal/Tests/Component/Utility/UnicodeTest.php
index ba1757f..8076f0c 100644
--- a/core/tests/Drupal/Tests/Component/Utility/UnicodeTest.php
+++ b/core/tests/Drupal/Tests/Component/Utility/UnicodeTest.php
@@ -376,7 +376,7 @@ class UnicodeTest extends TestCase {
* - (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 @@ class UnicodeTest extends TestCase {
['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;
}
/**