all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
From: Christophe TROESTLER <Christophe.TROESTLER@umons.ac.be>
To: Eli Zaretskii <eliz@gnu.org>
Cc: "36098@debbugs.gnu.org" <36098@debbugs.gnu.org>
Subject: bug#36098: 26.1; Incorrect epg--decode-percent-escape
Date: Wed, 5 Jun 2019 18:12:06 +0000	[thread overview]
Message-ID: <87muiv52bv.fsf@poincare.umons.ac.be> (raw)
In-Reply-To: <83imtkrlej.fsf@gnu.org>

[-- Attachment #1: Type: text/plain, Size: 544 bytes --]


On  5 June 2019 at 19:29 CEST, Eli Zaretskii <eliz@gnu.org> wrote:
>
>> From: Christophe TROESTLER <Christophe.TROESTLER@umons.ac.be>
>> CC: "36098@debbugs.gnu.org" <36098@debbugs.gnu.org>
>> Date: Wed, 5 Jun 2019 17:05:45 +0000
>> 
>> > What I mean was only to let that function return a unibyte string, and
>> > let the caller perform coding conversions.
>> 
>> I can do that.  To avoid repetitions, what about introducing epg--decode-percent-escape-as-utf-8?
>
> I think that would be fine, yes.

Updated patch doing that.


[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: 0001-epg-Use-unibyte-string-to-decode-percent-escape.patch --]
[-- Type: text/x-diff; name="0001-epg-Use-unibyte-string-to-decode-percent-escape.patch", Size: 2870 bytes --]

From 090ebf500ccfbc62d8e0748bcdedf770804c3f2d Mon Sep 17 00:00:00 2001
From: Christophe Troestler <Christophe.Troestler@umons.ac.be>
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 | 19 +++++++++----------
 1 file changed, 9 insertions(+), 10 deletions(-)

diff --git a/lisp/epg.el b/lisp/epg.el
index 0400716845..79fad1764b 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-as-utf-8 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-as-utf-8 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-as-utf-8 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,11 +2022,15 @@ 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))
 
+(defun epg--decode-percent-escape-as-utf-8 (string)
+  (decode-coding-string (epg--decode-percent-escape string) 'utf-8))
+
 (defun epg--decode-hexstring (string)
   (let ((index 0))
     (while (eq index (string-match "[0-9A-Fa-f][0-9A-Fa-f]" string index))
-- 
2.20.1


  reply	other threads:[~2019-06-05 18:12 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-06-05 13:49 bug#36098: 26.1; Incorrect epg--decode-percent-escape Christophe TROESTLER
2019-06-05 14:49 ` Eli Zaretskii
2019-06-05 15:53   ` Christophe TROESTLER
2019-06-05 16:57     ` Eli Zaretskii
2019-06-05 17:05       ` Christophe TROESTLER
2019-06-05 17:29         ` Eli Zaretskii
2019-06-05 18:12           ` Christophe TROESTLER [this message]
2019-06-22  9:26             ` Eli Zaretskii

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=87muiv52bv.fsf@poincare.umons.ac.be \
    --to=christophe.troestler@umons.ac.be \
    --cc=36098@debbugs.gnu.org \
    --cc=eliz@gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this external index

	https://git.savannah.gnu.org/cgit/emacs.git
	https://git.savannah.gnu.org/cgit/emacs/org-mode.git

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.