]> git.eshelyaron.com Git - emacs.git/commitdiff
Convert NUL-containing NSString objects to Lisp strings correctly
authorMattias Engdegård <mattiase@acm.org>
Tue, 18 Jul 2023 13:42:55 +0000 (15:42 +0200)
committerMattias Engdegård <mattiase@acm.org>
Tue, 18 Jul 2023 13:51:37 +0000 (15:51 +0200)
This cures the inability to paste text containing NUL from other
applications on macOS, introduced by mistake in 7e3c2b553f
(bug#64697).

* src/nsfns.m ([NSString lispString]): Use make_string instead of
build_string which relies on NUL-termination.

src/nsfns.m

index 8804a7df7cfbce394738bb066184a6ed2269b7c1..5ae2cc77bb227f4e936e17f4e06bdc64741c2864 100644 (file)
@@ -3829,7 +3829,9 @@ all_nonzero_ascii (unsigned char *str, ptrdiff_t n)
 /* Make a Lisp string from an NSString.  */
 - (Lisp_Object)lispString
 {
-  return build_string ([self UTF8String]);
+  // make_string behaves predictably and correctly with UTF-8 input.
+  return make_string ([self UTF8String],
+                      [self lengthOfBytesUsingEncoding: NSUTF8StringEncoding]);
 }
 @end