Even now that http://api.drupal.org/api/function/truncate_utf8/6 truncates to a specified number of characters instead of bytes (http://drupal.org/node/200185), http://api.drupal.org/api/function/node_teaser/6 can still return a string shorter than it is supposed to.

Simple fix: change

// If we have a short body, the entire body is the teaser.
  if (strlen($body) <= $size) {
    return $body;
  }

to

// If we have a short body, the entire body is the teaser.
  if (drupal_strlen($body) <= $size) {
    return $body;
  }
CommentFileSizeAuthor
#1 node_teaser_utf8.patch515 bytespancho

Comments

pancho’s picture

Status: Active » Needs review
StatusFileSize
new515 bytes

Yep, that was an easy fix. Works now as advertised.

gpk’s picture

Status: Needs review » Reviewed & tested by the community

Works fine. Used this sample code:

$s = 'éêëìí. Hi.';
print drupal_strlen($s) .', '. strlen($s) .'<br />'; // outputs 10, 15
print node_teaser($s, NULL, 13);

Before the patch, the output is
10, 15
éêëìí.

After the patch it is
10, 15
éêëìí. Hi.

Tested with other values of $size also.

gábor hojtsy’s picture

Status: Reviewed & tested by the community » Fixed

Thanks, committed.

Anonymous’s picture

Status: Fixed » Closed (fixed)

Automatically closed -- issue fixed for two weeks with no activity.