From 6464a8d702d56f26d34d989a9182396cdc6197a8 Mon Sep 17 00:00:00 2001 From: Michael Albinus Date: Sun, 6 May 2018 12:39:36 +0200 Subject: [PATCH] Fix Bug#31272 * lisp/net/tramp-sh.el (tramp-do-file-attributes-with-ls) (tramp-do-directory-files-and-attributes-with-stat) (tramp-sh-handle-insert-directory): Use "--show-control-chars". (tramp-convert-file-attributes): Decode multibyte strings, produced by "stat". (Bug#31272) * test/lisp/net/tramp-tests.el (tramp--test-utf8): Extend test. --- lisp/net/tramp-sh.el | 22 +++++++++++------ test/lisp/net/tramp-tests.el | 47 ++++++++++++++++++------------------ 2 files changed, 38 insertions(+), 31 deletions(-) diff --git a/lisp/net/tramp-sh.el b/lisp/net/tramp-sh.el index 58982e58bb1..9ea23a4edb5 100644 --- a/lisp/net/tramp-sh.el +++ b/lisp/net/tramp-sh.el @@ -1301,7 +1301,8 @@ component is used as the target of the symlink." ;; On systems which have no quoting style, file names ;; with special characters could fail. (cond - ((tramp-get-ls-command-with vec "--quoting-style=c")) + ((tramp-get-ls-command-with + vec "--quoting-style=literal --show-control-chars")) ((tramp-get-ls-command-with vec "-w")) (t "")) (tramp-shell-quote-argument localname))) @@ -1833,7 +1834,8 @@ be non-negative integers." ;; On systems which have no quoting style, file names with special ;; characters could fail. (cond - ((tramp-get-ls-command-with vec "--quoting-style=shell")) + ((tramp-get-ls-command-with + vec "--quoting-style=literal --show-control-chars")) ((tramp-get-ls-command-with vec "-w")) (t "")) (tramp-get-remote-stat vec) @@ -2635,8 +2637,11 @@ The method used must be an out-of-band method." filename switches wildcard full-directory-p) (when (stringp switches) (setq switches (split-string switches))) - (when (tramp-get-ls-command-with v "--quoting-style=literal") - (setq switches (append switches '("--quoting-style=literal")))) + (when (tramp-get-ls-command-with + v "--quoting-style=literal --show-control-chars") + (setq switches + (append + switches '("--quoting-style=literal" "--show-control-chars")))) (unless (tramp-get-ls-command-with v "--dired") (setq switches (delete "--dired" switches))) (when wildcard @@ -5135,11 +5140,12 @@ Return ATTR." (when (string-match "^d" (nth 8 attr)) (setcar attr t)) ;; Convert symlink from `tramp-do-file-attributes-with-stat'. + ;; Decode also multibyte string. (when (consp (car attr)) - (if (and (stringp (caar attr)) - (string-match ".+ -> .\\(.+\\)." (caar attr))) - (setcar attr (match-string 1 (caar attr))) - (setcar attr nil))) + (setcar attr + (and (stringp (caar attr)) + (string-match ".+ -> .\\(.+\\)." (caar attr)) + (decode-coding-string (match-string 1 (caar attr)) 'utf-8)))) ;; Set file's gid change bit. (setcar (nthcdr 9 attr) (if (numberp (nth 3 attr)) diff --git a/test/lisp/net/tramp-tests.el b/test/lisp/net/tramp-tests.el index 1843be71862..15187efdd33 100644 --- a/test/lisp/net/tramp-tests.el +++ b/test/lisp/net/tramp-tests.el @@ -4697,29 +4697,30 @@ Use the `ls' command." (coding-system-change-eol-conversion utf8 'unix))) (apply 'tramp--test-check-files - (if (tramp--test-expensive-test) - (delete-dups - (mapcar - ;; Use all available language specific snippets. Filter - ;; out strings which use unencodable characters. Remove - ;; slash or newline. Not Tramp's business. - (lambda (x) - (setq x (eval (cdr (assoc 'sample-text x)))) - (unless (or (null x) - (unencodable-char-position - 0 nil file-name-coding-system nil x) - (string-match "TaiViet" x)) - ;; ?\n and ?/ shouldn't be part of any file name. ?\t, - ;; ?. and ?? do not work for "smb" method. - (replace-regexp-in-string "[\t\n/.?]" "" x))) - language-info-alist)) - - (list - (unless (tramp--test-hpux-p) "Γυρίστε το Γαλαξία με Ώτο Στοπ") - (unless (tramp--test-hpux-p) - "أصبح بوسعك الآن تنزيل نسخة كاملة من موسوعة ويكيبيديا العربية لتصفحها بلا اتصال بالإنترنت") - "银河系漫游指南系列" - "Автостопом по гала́ктике"))))) + (append + (list + (unless (tramp--test-hpux-p) "Γυρίστε το Γαλαξία με Ώτο Στοπ") + (unless (tramp--test-hpux-p) + "أصبح بوسعك الآن تنزيل نسخة كاملة من موسوعة ويكيبيديا العربية لتصفحها بلا اتصال بالإنترنت") + "银河系漫游指南系列" + "Автостопом по гала́ктике" + ;; Use codepoints without a name. See Bug#31272. + "™›šbung") + + (when (tramp--test-expensive-test) + (delete-dups + (mapcar + ;; Use all available language specific snippets. Filter out + ;; strings which use unencodable characters. + (lambda (x) + (and + (stringp (setq x (eval (get-language-info (car x) 'sample-text)))) + (not (unencodable-char-position + 0 nil file-name-coding-system nil x)) + ;; ?\n and ?/ shouldn't be part of any file name. ?\t, + ;; ?. and ?? do not work for "smb" method. + (replace-regexp-in-string "[\t\n/.?]" "" x))) + language-info-alist))))))) (ert-deftest tramp-test39-utf8 () "Check UTF8 encoding in file names and file contents." -- 2.39.5