This is present in 7.x-3.0-rc3.

I want to rewrite the results of of a text field I enter the Maximum length (in my example 120 characters) and I check

  • Trim only on a word boundary
  • Add an ellipsis
  • Strip HTML tags
  • Remove whitespace

First of all I notice that the ellipsis is not formed as … instead of which it is 3 stops - is there any reason why not?

Secondly there is an issue of the rewriting of the results. With a 'normal' node it truncates precisely on or before 120 characters, actually it trims at 117 characters plus the 3 dots. However in the conditions of acceptance tests that we are running we entered abcd abcd abcd abcd abcd abcd abcd abcd abcd abcd abcd abcd abcd abcd abcd abcd abcd abcd abcd abcd abcd abcd abcd abcd abcd and the text did not truncate at 117 or 120, instead of which it allowed the overrun to 124 characters PLUS the 3 dots.

Comments

wapnik’s picture

It should not be touching the formation of an ellipsis, but however the field handler it partially rewrites may had changed in the meantime.

Anonymous’s picture

Project: Views Field Rewrite » Views (for Drupal 7)
Version: 7.x-1.x-dev » 7.x-3.0-rc3
Component: Code » User interface

Sorry wapnik. I went through the views_trim_text function and it is certainly not down to Views Field Rewrite, it is a Views issue.

Changing project to Views

In the views_trim_text:

function views_trim_text($alter, $value) {
  if (drupal_strlen($value) > $alter['max_length']) {
    $value = drupal_substr($value, 0, $alter['max_length']);
    // TODO: replace this with cleanstring of ctools
    if (!empty($alter['word_boundary'])) {
      $regex = "(.*)\b.+";
      if (function_exists('mb_ereg')) {
        mb_regex_encoding('UTF-8');
        $found = mb_ereg($regex, $value, $matches);
      }
      else {
        $found = preg_match("/$regex/us", $value, $matches);
      }
      if ($found) {
        $value = $matches[1];
      }
    }
    // Remove scraps of HTML entities from the end of a strings
    $value = rtrim(preg_replace('/(?:<(?!.+>)|&(?!.+;)).*$/us', '', $value));

    if (!empty($alter['ellipsis'])) {
      $value .= t('...');
    }
  }
  if (!empty($alter['html'])) {
    $value = _filter_htmlcorrector($value);
  }

  return $value;
}
dawehner’s picture

Status: Active » Closed (works as designed)

First of all I notice that the ellipsis is not formed as … instead of which it is 3 stops - is there any reason why not?

This are probably historic reasons. You can always create patches.

Secondly there is an issue of the rewriting of the results. With a 'normal' node it truncates precisely on or before 120 characters, actually it trims at 117 characters plus the 3 dots. However in the conditions of acceptance tests that we are running we entered abcd abcd abcd abcd abcd abcd abcd abcd abcd abcd abcd abcd abcd abcd abcd abcd abcd abcd abcd abcd abcd abcd abcd abcd abcd and the text did not truncate at 117 or 120, instead of which it allowed the overrun to 124 characters PLUS the 3 dots.

You seem to expect taht the ellipsis is part of the 120 remaining characters but it's currently not. The text itself is truncated to a maximimum length and the 3 dots are added at the end. Your description of 117 characters seems to be just luck.
Sure this behavior could be changed but this behavior existed for quite some time and i see advantages on both sides.
So update the status here.

Anonymous’s picture

Thanks for your comment dereine.

Anonymous’s picture

Issue summary: View changes

Better worded