From: Stefan Monnier Date: Mon, 19 Oct 2020 17:03:41 +0000 (-0400) Subject: * lisp/mail/rfc2231.el (rfc2231-decode-encoded-string): Fix match data error X-Git-Tag: emacs-28.0.90~5536 X-Git-Url: http://git.eshelyaron.com/gitweb/?a=commitdiff_plain;h=ed9520b38e1fb8dc45a9eb4227ceb49387843de2;p=emacs.git * 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. --- 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.