--- modules/comment.module	Wed Mar 24 23:01:07 2004
+++ modules/comment.module	Mon Apr  5 23:00:19 2004
@@ -277,7 +277,7 @@ function comment_post($edit) {
     $edit["subject"] = strip_tags($edit["subject"]);
 
     if ($edit["subject"] == "") {
-      $edit["subject"] = substr(strip_tags($edit["comment"]), 0, 29);
+      $edit["subject"] = truncate_utf8(strip_tags($edit["comment"]), 0, 29);
     }
 
     /*
--- includes/common.inc	Thu Apr  1 18:32:29 2004
+++ includes/common.inc	Mon Apr  5 23:00:00 2004
@@ -532,6 +532,23 @@ function drupal_specialchars($input, $qu
   return htmlspecialchars($input, $quotes);
 }
 
+/*
+* UTF-8-safe string truncation
+* If the end position is in the middle of a UTF-8-sequence, it scans backwards until
+* the beginning of the sequence.
+*/
+function truncate_utf8($string, $len) {
+  $slen = strlen($string);
+  if ($slen <= $len) {
+    return $string;
+  }
+  if ((ord($string[$len]) < 0x80) || (ord($string[$len]) >= 0xC0)) {
+    return substr($string, 0, $len);
+  }
+  while (ord($string[--$len]) < 0xC0) { };
+  return substr($string, 0, $len);
+}
+
 /**
  * @name Validation
  * @ingroup common
