From: Lars Ingebrigtsen Date: Sat, 6 Nov 2021 21:43:22 +0000 (+0100) Subject: Fix nul-terminated text/* strings from some programs X-Git-Tag: emacs-29.0.90~3671^2~167 X-Git-Url: http://git.eshelyaron.com/gitweb/?a=commitdiff_plain;h=973f0aa5595de878f5c01b0b9365dfb57e54f7f4;p=emacs.git Fix nul-terminated text/* strings from some programs * lisp/yank-media.el (yank-media--get-selection): Some programs nul-terminate text/* strings. Fix that. --- diff --git a/lisp/yank-media.el b/lisp/yank-media.el index 5cc5e366e9c..bc104a30c9f 100644 --- a/lisp/yank-media.el +++ b/lisp/yank-media.el @@ -76,9 +76,14 @@ the `register-yank-media-handler' mechanism." (defun yank-media--get-selection (type) (when-let ((data (gui-get-selection 'CLIPBOARD type))) - (if-let ((charset (get-text-property 0 'charset data))) - (encode-coding-string data charset) - data))) + (when-let ((charset (get-text-property 0 'charset data))) + (setq date (encode-coding-string data charset))) + ;; Some programs add a nul character at the end of text/* + ;; selections. Remove that. + (when (and (string-match-p "\\`text/" (symbol-name type)) + (zerop (elt data (1- (length data))))) + (setq data (substring data 0 (1- (length data))))) + data)) ;;;###autoload (defun register-yank-media-handler (types handler)