Index: node.module
===================================================================
RCS file: /cvs/drupal/drupal/modules/node/node.module,v
retrieving revision 1.889
diff -r1.889 node.module
290,291c290,297
<   $position = 0;
<   // Cache the reverse of the teaser.
---
> 
>   // Reset $size to the actual length of the UTF8 string -- which might not be the same as $size.
>   $size = strlen($teaser);
> 
>   // How much to cut off the end of body to make the teaser. Initialize it to the largest possible value.
>   $min_length = $size;
> 
>   // Store the reverse of the teaser.  We use strpos on the reversed needle and haystack for speed.
294,298c300,301
<   // In some cases, no delimiter has been specified. In this case, we try to
<   // split at paragraph boundaries.
<   $breakpoints = array('</p>' => 0, '<br />' => 6, '<br>' => 4, "\n" => 1);
<   // We use strpos on the reversed needle and haystack for speed.
<   foreach ($breakpoints as $point => $offset) {
---
>   // If the delimiter has not been specified, try to split at paragraph boundaries.
>   foreach (array('</p>' => 0, '<br />' => 6, '<br>' => 4, "\n" => 1) as $point => $offset) {
301,302c304
<       $position = - $length - $offset;
<       return ($position == 0) ? $teaser : substr($teaser, 0, $position);
---
>       $min_length = min($length + $offset, $min_length);
306,314c308,314
<   // When even the first paragraph is too long, we try to split at the end of
<   // the last full sentence.
<   $breakpoints = array('. ' => 1, '! ' => 1, '? ' => 1, '。' => 0, '؟ ' => 1);
<   $min_length = strlen($reversed);
<   foreach ($breakpoints as $point => $offset) {
<     $length = strpos($reversed, strrev($point));
<     if ($length !== FALSE) {
<       $min_length = min($length, $min_length);
<       $position = 0 - $length - $offset;
---
>   // When the first paragraph is too long, we try to split at the end of the last full sentence.
>   if ($min_length == strlen($reversed)) {
>     foreach (array('. ' => 1, '! ' => 1, '? ' => 1, '。' => 0, '؟ ' => 1) as $point => $offset) {
>       $length = strpos($reversed, strrev($point));
>       if ($length !== FALSE) {
>         $min_length = min($length + $offset, $min_length);
>       }
317c317,318
<   return ($position == 0) ? $teaser : substr($teaser, 0, $position);
---
>   
>   return ($min_length == strlen($teaser)) ? $teaser : substr($teaser, 0, 0 - $min_length);
