all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
From: Stefan Monnier <monnier@iro.umontreal.ca>
To: Robert Pluim <rpluim@gmail.com>
Cc: emacs-devel@gnu.org
Subject: Re: master d57bb0c: Treat passed strings as raw-text when percent-escaping in epg
Date: Thu, 12 Dec 2019 08:58:33 -0500	[thread overview]
Message-ID: <jwv4ky5vfls.fsf-monnier+emacs@gnu.org> (raw)
In-Reply-To: <20191212073738.9C7A3200E3@vcs0.savannah.gnu.org> (Robert Pluim's message of "Thu, 12 Dec 2019 02:37:38 -0500 (EST)")

Hi Robert,

>     The strings contained in gpg keys can contain UTF-8 data, but can also
>     use percent-escapes to encode non-ASCII chars.  When converting those
>     escapes, use 'raw-text' coding system rather than 'string-to-unibyte',
>     since the latter signals an error for non-ASCII characters.

I don't quite understand: "can contain UTF-8 data" seems odd here since
you're calling `encode-coding-string` whose input argument is a sequence
of characters whereas "UTF-8 data" can only be found in sequences of bytes.

Did you mean "can contain non-ASCII characters"?

The other problem with the above description is the "raw-text" since
it's far from clear what it means (personally I really have no idea
what is "raw text" and the way Emacs understands "raw text" is more or
less "EOL-separated lines of bytes" which does not seem to match your
description since string-to-unibyte doesn't signal errors when
encountering bytes).

Looking at the code, I see that the only caller of
`epg--decode-percent-escape` seems to be
`epg--decode-percent-escape-utf-8` which decodes the bytes returned by
`epg--decode-percent-escape` using `utf-8` so I think it makes more
sense to encode using `utf-8` than `raw-text`, WDYT?


        Stefan


diff --git a/lisp/epg.el b/lisp/epg.el
index 5466716e34..e2ce68e161 100644
--- a/lisp/epg.el
+++ b/lisp/epg.el
@@ -2032,7 +2032,7 @@ epg-edit-key
     (epg-reset context)))
 
 (defun epg--decode-percent-escape (string)
-  (setq string (encode-coding-string string 'raw-text))
+  ;; `string' is assumed to be a sequence of *bytes*.
   (let ((index 0))
     (while (string-match "%\\(\\(%\\)\\|\\([[:xdigit:]][[:xdigit:]]\\)\\)"
 			 string index)
@@ -2047,7 +2047,10 @@ epg--decode-percent-escape
     string))
 
 (defun epg--decode-percent-escape-as-utf-8 (string)
-  (decode-coding-string (epg--decode-percent-escape string) 'utf-8))
+  (decode-coding-string
+   (epg--decode-percent-escape
+    (encode-coding-string string 'utf-8))
+   'utf-8))
 
 (defun epg--decode-hexstring (string)
   (let ((index 0))




       reply	other threads:[~2019-12-12 13:58 UTC|newest]

Thread overview: 19+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <20191212073737.19923.49084@vcs0.savannah.gnu.org>
     [not found] ` <20191212073738.9C7A3200E3@vcs0.savannah.gnu.org>
2019-12-12 13:58   ` Stefan Monnier [this message]
2019-12-12 15:19     ` master d57bb0c: Treat passed strings as raw-text when percent-escaping in epg Robert Pluim
2019-12-12 15:28       ` Eli Zaretskii
2019-12-12 15:33         ` Robert Pluim
2019-12-12 15:36           ` Eli Zaretskii
2019-12-12 15:30       ` Robert Pluim
2019-12-12 15:45         ` Eli Zaretskii
2019-12-12 16:17           ` Robert Pluim
2019-12-16 16:06           ` Stefan Monnier
2019-12-12 15:42       ` Andreas Schwab
2019-12-12 16:11         ` Robert Pluim
2019-12-12 16:33           ` Andreas Schwab
2019-12-12 16:39             ` Robert Pluim
2019-12-12 16:55               ` Andreas Schwab
2019-12-12 17:57           ` Eli Zaretskii
2019-12-13  9:40             ` Robert Pluim
2019-12-13 10:33               ` Eli Zaretskii
2019-12-16 16:21       ` Stefan Monnier
2019-12-16 16:38         ` Robert Pluim

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=jwv4ky5vfls.fsf-monnier+emacs@gnu.org \
    --to=monnier@iro.umontreal.ca \
    --cc=emacs-devel@gnu.org \
    --cc=rpluim@gmail.com \
    /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.