]> git.eshelyaron.com Git - emacs.git/commitdiff
Read non-ASCII chars from unibyte string sources as raw bytes
authorMattias Engdegård <mattiase@acm.org>
Sat, 5 Jul 2025 11:20:18 +0000 (13:20 +0200)
committerEshel Yaron <me@eshelyaron.com>
Thu, 24 Jul 2025 07:48:30 +0000 (09:48 +0200)
Previously, latin-1 was incorrectly assumed (bug#70988).

* src/lread.c (readchar): Convert to raw byte.
* test/src/lread-tests.el (lread-unibyte-string-source): New test.

(cherry picked from commit d13693ef4ec9428e2356b0de29913d533c5c4382)

src/lread.c
test/src/lread-tests.el

index 6cd6735a215574322d06de910195308d14db7129..5d9bdb065e8f4bef3bfac8a637527fefdc0f41dd 100644 (file)
@@ -382,6 +382,8 @@ readchar (Lisp_Object readcharfun, bool *multibyte)
       else
        {
          c = SREF (readcharfun, read_from_string_index_byte);
+         if (!ASCII_CHAR_P (c))
+           c = BYTE8_TO_CHAR (c);
          read_from_string_index++;
          read_from_string_index_byte++;
        }
index d832cc9aa4ebcd6d2149f884b0fe65e305bb44c2..d9b31a6c43847797f44b1261123e26936ce3aa6b 100644 (file)
@@ -392,4 +392,10 @@ literals (Bug#20852)."
          (val (read (lambda () (pop s)))))
     (should (equal (symbol-name val) "A∪ÿ"))))
 
+(ert-deftest lread-unibyte-string-source ()
+  (let* ((src "\"a\xff\"")
+         (val (read src)))
+    (should (equal val "a\xff"))        ; not "aÿ"
+    (should-not (multibyte-string-p val))))
+
 ;;; lread-tests.el ends here