From 9ddec89e422d0dd6e9069731b8f2dd2c90aa5607 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. --- 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 3a66030c9d0..d38250d4e09 100644 --- a/lisp/net/tramp-cmds.el +++ b/lisp/net/tramp-cmds.el @@ -368,7 +368,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 12ad14e0900..c23eed0bc1b 100644 --- a/lisp/net/tramp.el +++ b/lisp/net/tramp.el @@ -1826,14 +1826,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 @@ -2233,6 +2228,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 @@ -5033,7 +5036,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)) "") @@ -5108,7 +5111,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))))