Commit 7ad74a99 authored by alexpott's avatar alexpott

Issue #2279617 by thedavidmeister, mgifford: Fixed _filter_url_trim() should...

Issue #2279617 by thedavidmeister, mgifford: Fixed _filter_url_trim() should use Unicode::truncate().
parent fce11dd7
......@@ -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;
......
......@@ -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) {
......
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