diff options
| author | Chong Yidong | 2012-04-24 13:34:50 +0800 |
|---|---|---|
| committer | Chong Yidong | 2012-04-24 13:34:50 +0800 |
| commit | acb71f1dad7b265eef5c5111bf15c3c612d1b19f (patch) | |
| tree | ef68c0cb9e991bdf7ddf7b0a98515277837fd629 | |
| parent | 9be2fd9b4f96bd00d222ae8ce13f8bb39802f930 (diff) | |
| download | emacs-acb71f1dad7b265eef5c5111bf15c3c612d1b19f.tar.gz emacs-acb71f1dad7b265eef5c5111bf15c3c612d1b19f.zip | |
Ensure that X selection convertors properly encode returned strings.
Though not itself a regression, this bug was exposed by the support
for MULTIPLE selections, which is new to Emacs 24 (see Bug#11315).
* lisp/select.el (xselect--encode-string): New function, split from
xselect-convert-to-string.
(xselect-convert-to-string): Use it.
(xselect-convert-to-filename, xselect-convert-to-os)
(xselect-convert-to-host, xselect-convert-to-user): Ensure that
returned strings are properly encoded.
| -rw-r--r-- | lisp/ChangeLog | 9 | ||||
| -rw-r--r-- | lisp/select.el | 47 |
2 files changed, 34 insertions, 22 deletions
diff --git a/lisp/ChangeLog b/lisp/ChangeLog index eb293610a67..834f54bc96e 100644 --- a/lisp/ChangeLog +++ b/lisp/ChangeLog | |||
| @@ -1,3 +1,12 @@ | |||
| 1 | 2012-04-24 Chong Yidong <cyd@gnu.org> | ||
| 2 | |||
| 3 | * select.el (xselect--encode-string): New function, split from | ||
| 4 | xselect-convert-to-string. | ||
| 5 | (xselect-convert-to-string): Use it. | ||
| 6 | (xselect-convert-to-filename, xselect-convert-to-os) | ||
| 7 | (xselect-convert-to-host, xselect-convert-to-user): Ensure that | ||
| 8 | returned strings are properly encoded (Bug#11315). | ||
| 9 | |||
| 1 | 2012-04-22 Chong Yidong <cyd@gnu.org> | 10 | 2012-04-22 Chong Yidong <cyd@gnu.org> |
| 2 | 11 | ||
| 3 | * simple.el (delete-active-region): Move to killing custom group. | 12 | * simple.el (delete-active-region): Move to killing custom group. |
diff --git a/lisp/select.el b/lisp/select.el index 0260eba4682..3948fcc5456 100644 --- a/lisp/select.el +++ b/lisp/select.el | |||
| @@ -213,30 +213,25 @@ two markers or an overlay. Otherwise, it is nil." | |||
| 213 | (defun xselect--int-to-cons (n) | 213 | (defun xselect--int-to-cons (n) |
| 214 | (cons (ash n -16) (logand n 65535))) | 214 | (cons (ash n -16) (logand n 65535))) |
| 215 | 215 | ||
| 216 | (defun xselect-convert-to-string (_selection type value) | 216 | (defun xselect--encode-string (type str &optional can-modify) |
| 217 | (let (str coding) | 217 | (when str |
| 218 | ;; Get the actual string from VALUE. | 218 | ;; If TYPE is nil, this is a local request; return STR as-is. |
| 219 | (cond ((stringp value) | 219 | (if (null type) |
| 220 | (setq str value)) | 220 | str |
| 221 | ((setq value (xselect--selection-bounds value)) | 221 | ;; Otherwise, encode STR. |
| 222 | (with-current-buffer (nth 2 value) | 222 | (let ((coding (or next-selection-coding-system |
| 223 | (setq str (buffer-substring (nth 0 value) | 223 | selection-coding-system))) |
| 224 | (nth 1 value)))))) | ||
| 225 | (when str | ||
| 226 | ;; If TYPE is nil, this is a local request, thus return STR as | ||
| 227 | ;; is. Otherwise, encode STR. | ||
| 228 | (if (not type) | ||
| 229 | str | ||
| 230 | (setq coding (or next-selection-coding-system selection-coding-system)) | ||
| 231 | (if coding | 224 | (if coding |
| 232 | (setq coding (coding-system-base coding))) | 225 | (setq coding (coding-system-base coding))) |
| 233 | (let ((inhibit-read-only t)) | 226 | (let ((inhibit-read-only t)) |
| 234 | ;; Suppress producing escape sequences for compositions. | 227 | ;; Suppress producing escape sequences for compositions. |
| 228 | ;; But avoid modifying the string if it's a buffer name etc. | ||
| 229 | (unless can-modify (setq str (substring str 0))) | ||
| 235 | (remove-text-properties 0 (length str) '(composition nil) str) | 230 | (remove-text-properties 0 (length str) '(composition nil) str) |
| 231 | ;; TEXT is a polymorphic target. Select the actual type | ||
| 232 | ;; from `UTF8_STRING', `COMPOUND_TEXT', `STRING', and | ||
| 233 | ;; `C_STRING'. | ||
| 236 | (if (eq type 'TEXT) | 234 | (if (eq type 'TEXT) |
| 237 | ;; TEXT is a polymorphic target. We must select the | ||
| 238 | ;; actual type from `UTF8_STRING', `COMPOUND_TEXT', | ||
| 239 | ;; `STRING', and `C_STRING'. | ||
| 240 | (if (not (multibyte-string-p str)) | 235 | (if (not (multibyte-string-p str)) |
| 241 | (setq type 'C_STRING) | 236 | (setq type 'C_STRING) |
| 242 | (let (non-latin-1 non-unicode eight-bit) | 237 | (let (non-latin-1 non-unicode eight-bit) |
| @@ -279,6 +274,14 @@ two markers or an overlay. Otherwise, it is nil." | |||
| 279 | (setq next-selection-coding-system nil) | 274 | (setq next-selection-coding-system nil) |
| 280 | (cons type str)))) | 275 | (cons type str)))) |
| 281 | 276 | ||
| 277 | (defun xselect-convert-to-string (_selection type value) | ||
| 278 | (let ((str (cond ((stringp value) value) | ||
| 279 | ((setq value (xselect--selection-bounds value)) | ||
| 280 | (with-current-buffer (nth 2 value) | ||
| 281 | (buffer-substring (nth 0 value) | ||
| 282 | (nth 1 value))))))) | ||
| 283 | (xselect--encode-string type str t))) | ||
| 284 | |||
| 282 | (defun xselect-convert-to-length (_selection _type value) | 285 | (defun xselect-convert-to-length (_selection _type value) |
| 283 | (let ((len (cond ((stringp value) | 286 | (let ((len (cond ((stringp value) |
| 284 | (length value)) | 287 | (length value)) |
| @@ -311,7 +314,7 @@ two markers or an overlay. Otherwise, it is nil." | |||
| 311 | 314 | ||
| 312 | (defun xselect-convert-to-filename (_selection _type value) | 315 | (defun xselect-convert-to-filename (_selection _type value) |
| 313 | (when (setq value (xselect--selection-bounds value)) | 316 | (when (setq value (xselect--selection-bounds value)) |
| 314 | (buffer-file-name (nth 2 value)))) | 317 | (xselect--encode-string 'TEXT (buffer-file-name (nth 2 value))))) |
| 315 | 318 | ||
| 316 | (defun xselect-convert-to-charpos (_selection _type value) | 319 | (defun xselect-convert-to-charpos (_selection _type value) |
| 317 | (when (setq value (xselect--selection-bounds value)) | 320 | (when (setq value (xselect--selection-bounds value)) |
| @@ -337,13 +340,13 @@ two markers or an overlay. Otherwise, it is nil." | |||
| 337 | (xselect--int-to-cons (max beg end)))))))) | 340 | (xselect--int-to-cons (max beg end)))))))) |
| 338 | 341 | ||
| 339 | (defun xselect-convert-to-os (_selection _type _size) | 342 | (defun xselect-convert-to-os (_selection _type _size) |
| 340 | (symbol-name system-type)) | 343 | (xselect--encode-string 'TEXT (symbol-name system-type))) |
| 341 | 344 | ||
| 342 | (defun xselect-convert-to-host (_selection _type _size) | 345 | (defun xselect-convert-to-host (_selection _type _size) |
| 343 | (system-name)) | 346 | (xselect--encode-string 'TEXT (system-name))) |
| 344 | 347 | ||
| 345 | (defun xselect-convert-to-user (_selection _type _size) | 348 | (defun xselect-convert-to-user (_selection _type _size) |
| 346 | (user-full-name)) | 349 | (xselect--encode-string 'TEXT (user-full-name))) |
| 347 | 350 | ||
| 348 | (defun xselect-convert-to-class (_selection _type _size) | 351 | (defun xselect-convert-to-class (_selection _type _size) |
| 349 | "Convert selection to class. | 352 | "Convert selection to class. |