diff --git a/src/ChangeLog b/src/ChangeLog
index 930eafbb3fb893b65a285d2e20aa722fd39c604f..ac900d15b367fe99c8baedf3992a95223d97c8e5 100644
--- a/src/ChangeLog
+++ b/src/ChangeLog
@@ -1,3 +1,9 @@
+2005-03-08  David Byers  <byers@lysator.liu.se>
+
+	* compatibility.el (lyskom-encode-coding-string): Renamed
+	functions used when detecting copy bug. Detect multibyte bug. 
+	This hopefully fixes bug 1524.
+
 2005-03-07  David Byers  <byers@lysator.liu.se>
 
 	* lyskom-rest.el (lyskom-face-default-p): New implementation since
diff --git a/src/compatibility.el b/src/compatibility.el
index a0f050119bf649e92dc8beb99d058f169990fa62..7a1a71a9cb21bebe3cf72d5b31f33145748f53b5 100644
--- a/src/compatibility.el
+++ b/src/compatibility.el
@@ -240,13 +240,30 @@ KEYS should be a string in the format used for saving keyboard macros
 ;; decode-coding-string such as those provided by APEL (part of TM and
 ;; often included in XEmacs)
 
-(defun lyskom-buggy-encode-coding-string (str coding-system) str)
+(defun lyskom-encode-coding-string-with-copy-bug (str coding-system) str)
 (eval-and-compile
   (if (let ((test "TEM")) (eq (lyskom-encode-coding-string test 'raw-text) test))
-      (progn (fset 'lyskom-buggy-encode-coding-string
+      (progn (fset 'lyskom-encode-coding-string-with-copy-bug
                    (symbol-function 'lyskom-encode-coding-string))
              (defun lyskom-encode-coding-string (str coding-system)
-               (copy-sequence (lyskom-buggy-encode-coding-string str coding-system))))))
+               (copy-sequence (lyskom-encode-coding-string-with-copy-bug
+                               str coding-system))))))
+
+;; Emacs 20.7, 21.2, 21.3 and CVS versions before 2005-02-14 have a bug
+;; where the result of encode-coding-string is sometimes a multibyte
+;; string. Detect this problem.
+
+(defun lyskom-encode-coding-string-with-multibyte-bug (str coding-system) str)
+(eval-and-compile
+  (if (lyskom-multibyte-string-p
+       (lyskom-encode-coding-string
+        (substring (concat "�" (make-string 1025 ?x)) 1) 'iso-8859-1))
+      (progn (fset 'lyskom-encode-coding-string-with-multibyte-bug
+                   (symbol-function 'lyskom-encode-coding-string))
+             (defun lyskom-encode-coding-string (str coding-system)
+               (string-make-unibyte
+                (lyskom-encode-coding-string-with-multibyte-bug str coding-system))))))
+
 
 (defun lyskom-buggy-decode-coding-string (str coding-system) str)
 (eval-and-compile