From e51f9046762a4f34ece910802aa7f2007303124d Mon Sep 17 00:00:00 2001 From: Lars Ingebrigtsen Date: Sat, 5 Feb 2022 07:00:50 +0100 Subject: [PATCH] Fix yank-media-types--format decoding * lisp/yank-media.el (yank-media-types--format): Check that we really have some nuls. --- lisp/yank-media.el | 37 ++++++++++++++++++++----------------- 1 file changed, 20 insertions(+), 17 deletions(-) diff --git a/lisp/yank-media.el b/lisp/yank-media.el index 9836082fb2a..8c758777247 100644 --- a/lisp/yank-media.el +++ b/lisp/yank-media.el @@ -162,23 +162,26 @@ non-supported selection data types." (when (zerop (elt data i)) (setf (aref stats (mod i 2)) (1+ (aref stats (mod i 2)))))) - ;; If we have more than 90% every-other nul, then it's - ;; pretty likely to be utf-16. - (cond - ((> (if (zerop (elt stats 1)) - 1 - (/ (float (elt stats 0)) - (float (elt stats 1)))) - 0.9) - ;; Big endian. - 'utf-16-be) - ((> (if (zerop (elt stats 0)) - 1 - (/ (float (elt stats 1)) - (float (elt stats 0)))) - 0.9) - ;; Little endian. - 'utf-16-le)))))) + ;; We have some nuls... + (and (not (and (zerop (elt stats 0)) + (zerop (elt stats 1)))) + ;; If we have more than 90% every-other nul, then it's + ;; pretty likely to be utf-16. + (cond + ((> (if (zerop (elt stats 1)) + 1 + (/ (float (elt stats 0)) + (float (elt stats 1)))) + 0.9) + ;; Big endian. + 'utf-16-be) + ((> (if (zerop (elt stats 0)) + 1 + (/ (float (elt stats 1)) + (float (elt stats 0)))) + 0.9) + ;; Little endian. + 'utf-16-le))))))) (if coding-system (decode-coding-string data coding-system) ;; Some programs add a nul character at the end of text/* -- 2.39.5