From 7ad74a99a22e232a088f12aff1e6a28a96edcdde Mon Sep 17 00:00:00 2001 From: Alex Pott 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 e2b09071cc8..fde8921de45 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 832257dca2d..b04a717dd2a 100644 --- a/core/modules/filter/src/Tests/FilterUnitTest.php +++ b/core/modules/filter/src/Tests/FilterUnitTest.php @@ -682,7 +682,7 @@ www.example.com with a newline in comments --> )); $tests = array( 'www.trimmed.com/d/ff.ext?a=1&b=2#a1' => array( - 'www.trimmed.com/d/ff...' => TRUE, + 'www.trimmed.com/d/f…' => TRUE, ), ); $this->assertFilteredString($filter, $tests); @@ -715,15 +715,17 @@ www.example.com with a newline in comments --> 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) {