From b9e1f7f39557e4a771caf151f3bc8dbbd408a074 Mon Sep 17 00:00:00 2001 From: Christophe Troestler Date: Wed, 5 Jun 2019 15:37:04 +0200 Subject: [PATCH] epg: Use unibyte string to decode percent escape MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Content-Type: text/plain; charset="utf-8" Fixes (decode-coding-string (epg--decode-percent-escape "D%C3%A9partement") 'utf-8) which should return "Département". --- lisp/epg.el | 18 +++++++----------- 1 file changed, 7 insertions(+), 11 deletions(-) diff --git a/lisp/epg.el b/lisp/epg.el index 0400716845..0c11a8c7c0 100644 --- a/lisp/epg.el +++ b/lisp/epg.el @@ -770,9 +770,7 @@ epg--status-USERID_HINT (user-id (match-string 2 string)) (entry (assoc key-id epg-user-id-alist))) (condition-case nil - (setq user-id (decode-coding-string - (epg--decode-percent-escape user-id) - 'utf-8)) + (setq user-id (epg--decode-percent-escape user-id)) (error)) (if entry (setcdr entry user-id) @@ -899,9 +897,7 @@ epg--status-*SIG (condition-case nil (if (eq (epg-context-protocol context) 'CMS) (setq user-id (epg-dn-from-string user-id)) - (setq user-id (decode-coding-string - (epg--decode-percent-escape user-id) - 'utf-8))) + (setq user-id (epg--decode-percent-escape user-id))) (error)) (if entry (setcdr entry user-id) @@ -1177,9 +1173,7 @@ epg--status-IMPORTED (user-id (match-string 2 string)) (entry (assoc key-id epg-user-id-alist))) (condition-case nil - (setq user-id (decode-coding-string - (epg--decode-percent-escape user-id) - 'utf-8)) + (setq user-id (epg--decode-percent-escape user-id)) (error)) (if entry (setcdr entry user-id) @@ -2020,6 +2014,7 @@ epg-edit-key (epg-reset context))) (defun epg--decode-percent-escape (string) + (setq string (string-to-unibyte string)) (let ((index 0)) (while (string-match "%\\(\\(%\\)\\|\\([0-9A-Fa-f][0-9A-Fa-f]\\)\\)" string index) @@ -2027,10 +2022,11 @@ epg--decode-percent-escape (setq string (replace-match "%" t t string) index (1- (match-end 0))) (setq string (replace-match - (string (string-to-number (match-string 3 string) 16)) + (byte-to-string + (string-to-number (match-string 3 string) 16)) t t string) index (- (match-end 0) 2)))) - string)) + (decode-coding-string string 'utf-8))) (defun epg--decode-hexstring (string) (let ((index 0)) -- 2.20.1