diff options
author | Stefan Monnier <monnier@iro.umontreal.ca> | 2020-10-19 13:03:41 -0400 |
---|---|---|
committer | Stefan Monnier <monnier@iro.umontreal.ca> | 2020-10-19 13:03:41 -0400 |
commit | ed9520b38e1fb8dc45a9eb4227ceb49387843de2 (patch) | |
tree | 65654a63682b7e88f071a1294307c137a589e7de /lisp/mail/rfc2231.el | |
parent | 4970e2c7ea1ec144f152829cb88416616b719d4a (diff) | |
download | emacs-ed9520b38e1fb8dc45a9eb4227ceb49387843de2.tar.gz emacs-ed9520b38e1fb8dc45a9eb4227ceb49387843de2.tar.bz2 emacs-ed9520b38e1fb8dc45a9eb4227ceb49387843de2.zip |
* lisp/mail/rfc2231.el (rfc2231-decode-encoded-string): Fix match data error
Get (match-string 3 string) earlier, in case `mm-charset-to-coding-system`
clobbers the match data.
Also, check that `string-match` succeeded before using its match data.
Diffstat (limited to 'lisp/mail/rfc2231.el')
-rw-r--r-- | lisp/mail/rfc2231.el | 36 |
1 files changed, 19 insertions, 17 deletions
diff --git a/lisp/mail/rfc2231.el b/lisp/mail/rfc2231.el index add099745b6..17da60e0bee 100644 --- a/lisp/mail/rfc2231.el +++ b/lisp/mail/rfc2231.el @@ -215,23 +215,25 @@ These look like: \"\\='en-us\\='This%20is%20%2A%2A%2Afun%2A%2A%2A\", \"\\='\\='This%20is%20%2A%2A%2Afun%2A%2A%2A\", or \"This is ***fun***\"." - (string-match "\\`\\(?:\\([^']+\\)?'\\([^']+\\)?'\\)?\\(.+\\)" string) - (let ((coding-system (mm-charset-to-coding-system - (match-string 1 string) nil t)) - ;;(language (match-string 2 string)) - (value (match-string 3 string))) - (mm-with-unibyte-buffer - (insert value) - (goto-char (point-min)) - (while (re-search-forward "%\\([[:xdigit:]][[:xdigit:]]\\)" nil t) - (insert - (prog1 - (string-to-number (match-string 1) 16) - (delete-region (match-beginning 0) (match-end 0))))) - ;; Decode using the charset, if any. - (if (memq coding-system '(nil ascii)) - (buffer-string) - (decode-coding-string (buffer-string) coding-system))))) + (if (not (string-match "\\`\\(?:\\([^']+\\)?'\\([^']+\\)?'\\)?\\(.+\\)\\'" + string)) + (error "Unrecognized RFC2231 format: %S" string) + (let ((value (match-string 3 string)) + ;;(language (match-string 2 string)) + (coding-system (mm-charset-to-coding-system + (match-string 1 string) nil t))) + (mm-with-unibyte-buffer + (insert value) + (goto-char (point-min)) + (while (re-search-forward "%\\([[:xdigit:]][[:xdigit:]]\\)" nil t) + (insert + (prog1 + (string-to-number (match-string 1) 16) + (delete-region (match-beginning 0) (match-end 0))))) + ;; Decode using the charset, if any. + (if (memq coding-system '(nil ascii)) + (buffer-string) + (decode-coding-string (buffer-string) coding-system)))))) (defun rfc2231-encode-string (param value) "Return a PARAM=VALUE string encoded according to RFC2231. |