From 9b0f1824d766139d3469c6837fb0b9db411a15b6 Mon Sep 17 00:00:00 2001 From: Eli Zaretskii Date: Tue, 22 Dec 2015 18:57:51 +0200 Subject: [PATCH] Fix decoding of text in URLs retrieved by EWW * lisp/net/eww.el (eww-render): Pass 'charset' to 'eww-display-raw'. Use the value of 'last-coding-system-used', if non-nil, to set 'buffer-file-coding-system' of the buffer where we show the URL. (eww-display-html, eww-display-raw): Decode the text correctly, using the charset found in the headers, and defaulting to UTF-8. If the user told us to use a specific encoding, override the charset from the headers. (Bug#22222) --- lisp/net/eww.el | 26 ++++++++++++-------------- 1 file changed, 12 insertions(+), 14 deletions(-) diff --git a/lisp/net/eww.el b/lisp/net/eww.el index 205be41a000..179010cf4cd 100644 --- a/lisp/net/eww.el +++ b/lisp/net/eww.el @@ -326,7 +326,8 @@ Currently this means either text/html or application/xhtml+xml." (or (cdr (assq 'charset (cdr content-type))) (eww-detect-charset (eww-html-p (car content-type))) "utf-8")))) - (data-buffer (current-buffer))) + (data-buffer (current-buffer)) + last-coding-system-used) ;; Save the https peer status. (with-current-buffer buffer (plist-put eww-data :peer (plist-get status :peer))) @@ -344,11 +345,13 @@ Currently this means either text/html or application/xhtml+xml." ((string-match-p "\\`image/" (car content-type)) (eww-display-image buffer)) (t - (eww-display-raw buffer encode))) + (eww-display-raw buffer (or encode charset 'utf-8)))) (with-current-buffer buffer (plist-put eww-data :url url) (eww-update-header-line-format) (setq eww-history-position 0) + (and last-coding-system-used + (set-buffer-file-coding-system last-coding-system-used)) (run-hooks 'eww-after-render-hook))) (kill-buffer data-buffer)))) @@ -394,13 +397,10 @@ Currently this means either text/html or application/xhtml+xml." (list 'base (list (cons 'href url)) (progn - (when (or (and encode - (not (eq charset encode))) - (not (eq charset 'utf-8))) - (condition-case nil - (decode-coding-region (point) (point-max) - (or encode charset)) - (coding-system-error nil))) + (setq encode (or encode charset 'utf-8)) + (condition-case nil + (decode-coding-region (point) (point-max) encode) + (coding-system-error nil)) (libxml-parse-html-region (point) (point-max)))))) (source (and (null document) (buffer-substring (point) (point-max))))) @@ -508,11 +508,9 @@ Currently this means either text/html or application/xhtml+xml." (let ((inhibit-read-only t)) (erase-buffer) (insert data) - (unless (eq encode 'utf-8) - (encode-coding-region (point-min) (1+ (length data)) 'utf-8) - (condition-case nil - (decode-coding-region (point-min) (1+ (length data)) encode) - (coding-system-error nil)))) + (condition-case nil + (decode-coding-region (point-min) (1+ (length data)) encode) + (coding-system-error nil))) (goto-char (point-min))))) (defun eww-display-image (buffer) -- 2.39.2