From b6aea1434f948ef64488cd56b333ce4a3a5c7b2a Mon Sep 17 00:00:00 2001 From: Michael Albinus Date: Fri, 6 Dec 2024 11:56:05 +0100 Subject: [PATCH] Better handling of "%" in Tramp user or host names * lisp/net/tramp.el (tramp-format-spec): New defun. (tramp-dissect-file-name, tramp-compute-multi-hops) (tramp-expand-args): * lisp/net/tramp-cmds.el (tramp-default-rename-file): Use it. (cherry picked from commit 9ddec89e422d0dd6e9069731b8f2dd2c90aa5607) --- lisp/net/tramp-cmds.el | 2 +- lisp/net/tramp.el | 23 +++++++++++++---------- 2 files changed, 14 insertions(+), 11 deletions(-) diff --git a/lisp/net/tramp-cmds.el b/lisp/net/tramp-cmds.el index 733c96fcfaa..516cfef3c89 100644 --- a/lisp/net/tramp-cmds.el +++ b/lisp/net/tramp-cmds.el @@ -366,7 +366,7 @@ function returns nil" (when (string-match-p (or (eval (car item) t) "") string) (setq tdra nil result - (format-spec + (tramp-format-spec (cdr item) (format-spec-make ?m method ?u user ?h host))))) result))) diff --git a/lisp/net/tramp.el b/lisp/net/tramp.el index 2b64c386e5c..0af6fe967ee 100644 --- a/lisp/net/tramp.el +++ b/lisp/net/tramp.el @@ -1823,14 +1823,9 @@ default values are used." user (tramp-find-user method user host) host (tramp-find-host method user host)) (when hop - ;; Replace placeholders. The hop could contain "%" - ;; which is not intended as format character, for - ;; example in USER%DOMAIN or POD%NAMESPACE. - (setq hop - (replace-regexp-in-string - (rx "%" (group (= 2 alnum))) "%%\\1" hop) - hop - (format-spec hop (format-spec-make ?h host ?u user)))))) + ;; Replace placeholders. + (setq + hop (tramp-format-spec hop (format-spec-make ?h host ?u user)))))) ;; Return result. (prog1 @@ -2236,6 +2231,14 @@ letter into the file name. This function removes it." (rx (regexp tramp-volume-letter-regexp) "/") "/" result)) (if quoted (file-name-quote result 'top) result)))) +(defun tramp-format-spec (format specification) + "Implement `format-spec' in Tramp. +FORMAT could contain \"%\" which is not intended as format character, +for example in USER%DOMAIN or POD%NAMESPACE." + (format-spec + (replace-regexp-in-string (rx "%" (group (= 2 alnum))) "%%\\1" format) + specification)) + ;;; Config Manipulation Functions: (defconst tramp-dns-sd-service-regexp @@ -5028,7 +5031,7 @@ Do not set it manually, it is used buffer-local in `tramp-get-lock-pid'.") (setq choices nil) ;; Replace placeholders. (setq proxy - (format-spec + (tramp-format-spec proxy (format-spec-make ?u (or (tramp-file-name-user (car target-alist)) "") @@ -5103,7 +5106,7 @@ a connection-local variable." (flatten-tree (mapcar (lambda (x) - (setq x (mapcar (lambda (y) (format-spec y spec)) x)) + (setq x (mapcar (lambda (y) (tramp-format-spec y spec)) x)) (unless (member "" x) x)) args)))) -- 2.39.2