From 7ad74a99a22e232a088f12aff1e6a28a96edcdde Mon Sep 17 00:00:00 2001
From: Alex Pott <alex.a.pott@googlemail.com>
Date: Tue, 17 Jun 2014 15:47:13 +0100
Subject: [PATCH] Issue #2279617 by thedavidmeister, mgifford: Fixed
 _filter_url_trim() should use Unicode::truncate().

---
 core/modules/filter/filter.module                | 8 ++++----
 core/modules/filter/src/Tests/FilterUnitTest.php | 8 +++++---
 2 files changed, 9 insertions(+), 7 deletions(-)

diff --git a/core/modules/filter/filter.module b/core/modules/filter/filter.module
index e2b09071cc87..fde8921de45e 100644
--- a/core/modules/filter/filter.module
+++ b/core/modules/filter/filter.module
@@ -6,6 +6,7 @@
  */
 
 use Drupal\Component\Utility\Html;
+use Drupal\Component\Utility\Unicode;
 use Drupal\Component\Utility\NestedArray;
 use Drupal\Component\Utility\String;
 use Drupal\Component\Utility\Xss;
@@ -1060,7 +1061,7 @@ function _filter_url_escape_comments($match, $escape = NULL) {
 }
 
 /**
- * Shortens long URLs to http://www.example.com/long/url...
+ * Shortens long URLs to http://www.example.com/long/url…
  */
 function _filter_url_trim($text, $length = NULL) {
   static $_length;
@@ -1068,9 +1069,8 @@ function _filter_url_trim($text, $length = NULL) {
     $_length = $length;
   }
 
-  // Use +3 for '...' string length.
-  if ($_length && strlen($text) > $_length + 3) {
-    $text = substr($text, 0, $_length) . '...';
+  if (isset($_length)) {
+    $text = Unicode::truncate($text, $_length, FALSE, TRUE);
   }
 
   return $text;
diff --git a/core/modules/filter/src/Tests/FilterUnitTest.php b/core/modules/filter/src/Tests/FilterUnitTest.php
index 832257dca2d3..b04a717dd2aa 100644
--- a/core/modules/filter/src/Tests/FilterUnitTest.php
+++ b/core/modules/filter/src/Tests/FilterUnitTest.php
@@ -682,7 +682,7 @@ function testUrlFilter() {
     ));
     $tests = array(
       'www.trimmed.com/d/ff.ext?a=1&b=2#a1' => array(
-        '<a href="http://www.trimmed.com/d/ff.ext?a=1&amp;b=2#a1">www.trimmed.com/d/ff...</a>' => TRUE,
+        '<a href="http://www.trimmed.com/d/ff.ext?a=1&amp;b=2#a1">www.trimmed.com/d/f…</a>' => TRUE,
       ),
     );
     $this->assertFilteredString($filter, $tests);
@@ -715,15 +715,17 @@ function assertFilteredString($filter, $tests) {
       foreach ($tasks as $value => $is_expected) {
         // Not using assertIdentical, since combination with strpos() is hard to grok.
         if ($is_expected) {
-          $success = $this->assertTrue(strpos($result, $value) !== FALSE, format_string('@source: @value found.', array(
+          $success = $this->assertTrue(strpos($result, $value) !== FALSE, format_string('@source: @value found. Filtered result: @result.', array(
             '@source' => var_export($source, TRUE),
             '@value' => var_export($value, TRUE),
+            '@result' => var_export($result, TRUE),
           )));
         }
         else {
-          $success = $this->assertTrue(strpos($result, $value) === FALSE, format_string('@source: @value not found.', array(
+          $success = $this->assertTrue(strpos($result, $value) === FALSE, format_string('@source: @value not found. Filtered result: @result.', array(
             '@source' => var_export($source, TRUE),
             '@value' => var_export($value, TRUE),
+            '@result' => var_export($result, TRUE),
           )));
         }
         if (!$success) {
-- 
GitLab