Subject: Re: bug#16733: messed up unicode chars in package description

From: Juanma Barranquero <[email-masked]>
Date: Wed, 19 Mar 2014 18:43:46 +0100

On Wed, Mar 19, 2014 at 6:11 PM, Eli Zaretskii <[email-masked]> wrote:

> I think you want url-insert from url-handlers.el.

Thanks.

So the following patch is a better fix. I'm OK with installing it,
though it is a bit more intrusive that the previous one.

   J

2014-03-19  Juanma Barranquero  <[email-masked]>

        * emacs-lisp/package.el: Fix bug#16733.
        (url-handlers): Require.
        (package--with-work-buffer): When LOCATION is a URL, use url-insert to
        properly decode the buffer.  Suggested by Eli Zaretskii <[email-masked]>.

=== modified file 'lisp/emacs-lisp/package.el'
--- lisp/emacs-lisp/package.el  2014-03-19 16:14:26 +0000
+++ lisp/emacs-lisp/package.el  2014-03-19 17:35:44 +0000
@@ -166,6 +166,7 @@
 (eval-when-compile (require 'cl-lib))

 (require 'tabulated-list)
+(require 'url-handlers)

 (defgroup package nil
   "Manager for Emacs Lisp packages."
@@ -770,15 +771,13 @@
 and evaluates BODY while that buffer is current.  This work
 buffer is killed afterwards.  Return the last value in BODY."
   (declare (indent 2) (debug t))
-  `(let* ((http (string-match "\\`https?:" ,location))
-         (buffer
-          (if http
-              (url-retrieve-synchronously (concat ,location ,file))
-            (generate-new-buffer "*package work buffer*"))))
+  `(let ((buffer (generate-new-buffer "*package work buffer*")))
      (prog1
         (with-current-buffer buffer
-          (if http
-              (progn (package-handle-response)
+          (if (string-match-p "\\`https?:" ,location)
+              (progn (url-insert (url-retrieve-synchronously
+                                  (concat ,location ,file)))
+                     (package-handle-response)
                      (re-search-forward "^$" nil 'move)
                      (forward-char)
                      (delete-region (point-min) (point)))
@@ -1531,8 +1530,7 @@
                        (setq readme-string (buffer-string))
                        t))
                 (error nil))
-              (let ((coding (detect-coding-string readme-string t)))
-                (insert (decode-coding-string readme-string coding t))))
+              (insert readme-string))
              ((file-readable-p readme)
               (insert-file-contents readme)
               (goto-char (point-max))))))))