From dc8aa15472dc5df5f903e6a3b150e2f03eeb2dd1 Mon Sep 17 00:00:00 2001 From: Michael Albinus Date: Sun, 2 Aug 2020 13:26:00 +0200 Subject: [PATCH] Fix Tramp portability issues * lisp/net/tramp-sh.el (tramp-set-remote-path): Replace "echo -n" by "printf", it isn't portable. * test/lisp/net/tramp-tests.el (tramp-test33-environment-variables) (tramp-test33-environment-variables-and-port-numbers): Do not use "echo -n", it isn't portable. (tramp--test-utf8): Filter out not displayable characters. --- lisp/net/tramp-sh.el | 2 +- test/lisp/net/tramp-tests.el | 25 +++++++++++++++---------- 2 files changed, 16 insertions(+), 11 deletions(-) diff --git a/lisp/net/tramp-sh.el b/lisp/net/tramp-sh.el index 9f37207def1..f9f0cbcc023 100644 --- a/lisp/net/tramp-sh.el +++ b/lisp/net/tramp-sh.el @@ -4079,7 +4079,7 @@ variable PATH." chunk (substring command 0 chunksize) command (substring command chunksize)) (tramp-send-command vec (format - "echo -n %s >>%s" + "printf \"%%b\" \"$*\" %s >>%s" (tramp-shell-quote-argument chunk) (tramp-shell-quote-argument tmpfile)))) (tramp-send-command vec (format ". %s" tmpfile)) diff --git a/test/lisp/net/tramp-tests.el b/test/lisp/net/tramp-tests.el index 19da15acafa..ac24fcf280a 100644 --- a/test/lisp/net/tramp-tests.el +++ b/test/lisp/net/tramp-tests.el @@ -4933,16 +4933,16 @@ INPUT, if non-nil, is a string sent to the process." (setenv "INSIDE_EMACS") (should (string-equal - (format "%s,tramp:%s" emacs-version tramp-version) - (funcall this-shell-command-to-string "echo -n ${INSIDE_EMACS:-bla}"))) + (format "%s,tramp:%s\n" emacs-version tramp-version) + (funcall this-shell-command-to-string "echo ${INSIDE_EMACS:-bla}"))) (let ((process-environment (cons (format "INSIDE_EMACS=%s,foo" emacs-version) process-environment))) (should (string-equal - (format "%s,foo,tramp:%s" emacs-version tramp-version) + (format "%s,foo,tramp:%s\n" emacs-version tramp-version) (funcall - this-shell-command-to-string "echo -n ${INSIDE_EMACS:-bla}")))) + this-shell-command-to-string "echo ${INSIDE_EMACS:-bla}")))) ;; Set a value. (let ((process-environment @@ -4952,7 +4952,7 @@ INPUT, if non-nil, is a string sent to the process." (string-match "foo" (funcall - this-shell-command-to-string (format "echo -n ${%s:-bla}" envvar))))) + this-shell-command-to-string (format "echo ${%s:-bla}" envvar))))) ;; Set the empty value. (let ((process-environment @@ -4962,7 +4962,7 @@ INPUT, if non-nil, is a string sent to the process." (string-match "bla" (funcall - this-shell-command-to-string (format "echo -n ${%s:-bla}" envvar)))) + this-shell-command-to-string (format "echo ${%s:-bla}" envvar)))) ;; Variable is set. (should (string-match @@ -4979,15 +4979,14 @@ INPUT, if non-nil, is a string sent to the process." (string-match "foo" (funcall - this-shell-command-to-string (format "echo -n ${%s:-bla}" envvar)))) + this-shell-command-to-string (format "echo ${%s:-bla}" envvar)))) (let ((process-environment (cons envvar process-environment))) ;; Variable is unset. (should (string-match "bla" (funcall - this-shell-command-to-string - (format "echo -n ${%s:-bla}" envvar)))) + this-shell-command-to-string (format "echo ${%s:-bla}" envvar)))) ;; Variable is unset. (should-not (string-match @@ -5026,7 +5025,7 @@ INPUT, if non-nil, is a string sent to the process." (should (string-match (number-to-string port) - (shell-command-to-string (format "echo -n $%s" envvar)))))) + (shell-command-to-string (format "echo $%s" envvar)))))) ;; Cleanup. (dolist (dir '("/mock:localhost#11111:" "/mock:localhost#22222:")) @@ -6051,6 +6050,12 @@ Use the `ls' command." (not (and (or (tramp--test-gvfs-p) (tramp--test-smb-p)) (unencodable-char-position 0 (length x) file-name-coding-system nil x))) + ;; Filter out not displayable characters. + (setq x (mapconcat + (lambda (y) + (and (char-displayable-p y) (char-to-string y))) + x "")) + (not (string-empty-p 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))) -- 2.39.2