[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: master d57bb0c: Treat passed strings as raw-text when percent-escapi
Re: master d57bb0c: Treat passed strings as raw-text when percent-escaping in epg
Thu, 12 Dec 2019 08:58:33 -0500
Gnus/5.13 (Gnus v5.13) Emacs/27.0.50 (gnu/linux)
> 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
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?
diff --git a/lisp/epg.el b/lisp/epg.el
index 5466716e34..e2ce68e161 100644
@@ -2032,7 +2032,7 @@ epg-edit-key
(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:]]\\)\\)"
@@ -2047,7 +2047,10 @@ epg--decode-percent-escape
(defun epg--decode-percent-escape-as-utf-8 (string)
- (decode-coding-string (epg--decode-percent-escape string) 'utf-8))
+ (encode-coding-string string 'utf-8))
(defun epg--decode-hexstring (string)
(let ((index 0))