emacs-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: master d57bb0c: Treat passed strings as raw-text when percent-escapi


From: Stefan Monnier
Subject: Re: master d57bb0c: Treat passed strings as raw-text when percent-escaping in epg
Date: Thu, 12 Dec 2019 08:58:33 -0500
User-agent: Gnus/5.13 (Gnus v5.13) Emacs/27.0.50 (gnu/linux)

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 via email to

[Prev in Thread] Current Thread [Next in Thread]