Commit 96a0d4fe authored by Stefan Monnier's avatar Stefan Monnier

* lisp/international/mule-cmds.el (encode-coding-char): Fix ASCII case

Don't bother with string-as-multibyte since `string` already returns
multibyte when needed.  Don't forget to encode when the string is
ASCII, e.g. for ebcdic case and to make sure we always return
a unibyte string.

* test/lisp/international/mule-tests.el (mule-cmds-tests--encode-ebcdic):
New test.
parent 997ac9f8
Pipeline #1823 failed with stage
in 50 minutes and 39 seconds
......@@ -2913,13 +2913,13 @@ If there's no description string for VALUE, return nil."
If CODING-SYSTEM can't safely encode CHAR, return nil.
The 3rd optional argument CHARSET, if non-nil, is a charset preferred
on encoding."
(let* ((str1 (string-as-multibyte (string char)))
(str2 (string-as-multibyte (string char char)))
(let* ((str1 (string char))
(str2 (string char char))
(found (find-coding-systems-string str1))
enc1 enc2 i1 i2)
(if (and (consp found)
(eq (car found) 'undecided))
(if (eq (car-safe found) 'undecided) ;Aka (not (multibyte-string-p str1))
;; `char' is ASCII.
(encode-coding-string str1 coding-system)
(when (memq (coding-system-base coding-system) found)
;; We must find the encoded string of CHAR. But, just encoding
;; CHAR will put extra control sequences (usually to designate
......@@ -36,6 +36,10 @@
(find-auto-coding "" (buffer-size)))
'(utf-8 . :coding)))))
(ert-deftest mule-cmds-tests--encode-ebcdic ()
(should (equal (encode-coding-char ?a 'ebcdic-int) "\201"))
(should (not (multibyte-string-p (encode-coding-char ?a 'utf-8)))))
;; Stop "Local Variables" above causing confusion when visiting this file.
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment