From e18c24b35a7cf9bb1b91288b706fa448ed28a7c2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mattias=20Engdeg=C3=A5rd?= Date: Thu, 9 Apr 2020 16:19:14 +0200 Subject: [PATCH] Set last-coding-system-used upon ASCII conversion bypass (bug#40407) Spotted by Kazuhiro Ito. * src/coding.c (code_convert_string): Set Vlast_coding_system if appropriate. * test/src/coding-tests.el (coding-nocopy-ascii): Add test. --- src/coding.c | 14 +++++++++----- test/src/coding-tests.el | 3 ++- 2 files changed, 11 insertions(+), 6 deletions(-) diff --git a/src/coding.c b/src/coding.c index 450c498f1e8..9848f983a81 100644 --- a/src/coding.c +++ b/src/coding.c @@ -9527,11 +9527,15 @@ code_convert_string (Lisp_Object string, Lisp_Object coding_system, && (EQ (CODING_ID_EOL_TYPE (coding.id), Qunix) || inhibit_eol_conversion || ! memchr (SDATA (string), encodep ? '\n' : '\r', bytes))) - return (nocopy - ? string - : (encodep - ? make_unibyte_string (SSDATA (string), bytes) - : make_multibyte_string (SSDATA (string), bytes, bytes))); + { + if (! norecord) + Vlast_coding_system_used = coding_system; + return (nocopy + ? string + : (encodep + ? make_unibyte_string (SSDATA (string), bytes) + : make_multibyte_string (SSDATA (string), bytes, bytes))); + } } else if (BUFFERP (dst_object)) { diff --git a/test/src/coding-tests.el b/test/src/coding-tests.el index 9f6fac3edd8..a741e233d39 100644 --- a/test/src/coding-tests.el +++ b/test/src/coding-tests.el @@ -393,7 +393,8 @@ (should-not (eq (decode-coding-string s coding nil) s)) (should-not (eq (encode-coding-string s coding nil) s)) (should (eq (decode-coding-string s coding t) s)) - (should (eq (encode-coding-string s coding t) s))) + (should (eq (encode-coding-string s coding t) s)) + (should (eq last-coding-system-used coding))) ;; With EOL conversion inhibited. (let ((inhibit-eol-conversion t))