From 26f24069c45974dfab5cf7033e5576f27fba28f6 Mon Sep 17 00:00:00 2001 From: Michael Albinus Date: Sun, 7 Jul 2024 19:34:37 +0200 Subject: [PATCH] Fix Tramp parser * lisp/net/tramp.el (tramp-host-with-port-regexp): Declare. (tramp-set-syntax): Set also `tramp-host-with-port-regexp'. (tramp-build-host-with-port-regexp): New defun. (tramp-host-with-port-regexp): Make it a defvar. (Bug#71972) * test/lisp/net/tramp-tests.el (tramp-test01-file-name-syntax) (tramp-test01-file-name-syntax-simplified) (tramp-test01-file-name-syntax-separate): Adapt tests. (cherry picked from commit f4c0459ed3edce33329744f60a0e389c20dc60a5) --- lisp/net/tramp.el | 21 ++++++++++++++++----- test/lisp/net/tramp-tests.el | 24 ++++++++++++++++++++++++ 2 files changed, 40 insertions(+), 5 deletions(-) diff --git a/lisp/net/tramp.el b/lisp/net/tramp.el index 53f1af50878..8b86a2aab4d 100644 --- a/lisp/net/tramp.el +++ b/lisp/net/tramp.el @@ -78,6 +78,7 @@ (defvar tramp-postfix-ipv6-regexp) (defvar tramp-postfix-host-format) (defvar tramp-postfix-host-regexp) +(defvar tramp-host-with-port-regexp) (defvar tramp-remote-file-name-spec-regexp) (defvar tramp-file-name-structure) (defvar tramp-file-name-regexp) @@ -878,6 +879,7 @@ to be set, depending on VALUE." tramp-postfix-ipv6-regexp (tramp-build-postfix-ipv6-regexp) tramp-postfix-host-format (tramp-build-postfix-host-format) tramp-postfix-host-regexp (tramp-build-postfix-host-regexp) + tramp-host-with-port-regexp (tramp-build-host-with-port-regexp) tramp-remote-file-name-spec-regexp (tramp-build-remote-file-name-spec-regexp) tramp-file-name-structure (tramp-build-file-name-structure) @@ -955,7 +957,8 @@ The `ftp' syntax does not support methods.") "Return `tramp-postfix-method-format' according to `tramp-syntax'." (tramp-lookup-syntax tramp-postfix-method-format-alist)) -(defvar tramp-postfix-method-format nil ; Init'd when defining `tramp-syntax'! +(defvar tramp-postfix-method-format + nil ; Initialized when defining `tramp-syntax'! "String matching delimiter between method and user or host names. The `ftp' syntax does not support methods. Used in `tramp-make-tramp-file-name'.") @@ -964,7 +967,8 @@ Used in `tramp-make-tramp-file-name'.") "Return `tramp-postfix-method-regexp'." (rx (literal (tramp-build-postfix-method-format)))) -(defvar tramp-postfix-method-regexp nil ; Init'd when defining `tramp-syntax'! +(defvar tramp-postfix-method-regexp + nil ; Initialized when defining `tramp-syntax'! "Regexp matching delimiter between method and user or host names. Derived from `tramp-postfix-method-format'.") @@ -1059,11 +1063,18 @@ Derived from `tramp-prefix-port-format'.") (defconst tramp-port-regexp (rx (+ digit)) "Regexp matching port numbers.") -(defconst tramp-host-with-port-regexp +(defun tramp-build-host-with-port-regexp () + "Return `tramp-host-with-port-regexp'." (rx - (group (regexp tramp-host-regexp)) + (group (| (regexp tramp-host-regexp) + (: (regexp tramp-prefix-ipv6-regexp) + (? (regexp tramp-ipv6-regexp)) + (regexp tramp-postfix-ipv6-regexp)))) (regexp tramp-prefix-port-regexp) - (group (regexp tramp-port-regexp))) + (group (regexp tramp-port-regexp)))) + +(defvar tramp-host-with-port-regexp + nil ; Initialized when defining `tramp-syntax'! "Regexp matching host names with port numbers.") (defconst tramp-postfix-hop-format "|" diff --git a/test/lisp/net/tramp-tests.el b/test/lisp/net/tramp-tests.el index d51286d2053..ece3fa17f54 100644 --- a/test/lisp/net/tramp-tests.el +++ b/test/lisp/net/tramp-tests.el @@ -330,6 +330,10 @@ is greater than 10. (should (tramp-tramp-file-p "/method:1.2.3.4:")) (should (tramp-tramp-file-p "/method:user@1.2.3.4:")) + ;; Using an IPv4 address with port. + (should (tramp-tramp-file-p "/method:1.2.3.4#1234:")) + (should (tramp-tramp-file-p "/method:user@1.2.3.4#1234:")) + ;; Using an IPv6 address. (should (tramp-tramp-file-p "/method:[::1]:")) (should (tramp-tramp-file-p "/method:user@[::1]:")) @@ -338,6 +342,10 @@ is greater than 10. (should (tramp-tramp-file-p "/method:[::ffff:1.2.3.4]:")) (should (tramp-tramp-file-p "/method:user@[::ffff:1.2.3.4]:")) + ;; Using an IPv6 address with port. + (should (tramp-tramp-file-p "/method:[::1]#1234:")) + (should (tramp-tramp-file-p "/method:user@[::1]#1234:")) + ;; Local file name part. (should (tramp-tramp-file-p "/method:::")) (should (tramp-tramp-file-p "/method::/:")) @@ -418,6 +426,10 @@ is greater than 10. (should (tramp-tramp-file-p "/1.2.3.4:")) (should (tramp-tramp-file-p "/user@1.2.3.4:")) + ;; Using an IPv4 address with port. + (should (tramp-tramp-file-p "/1.2.3.4#1234:")) + (should (tramp-tramp-file-p "/user@1.2.3.4#1234:")) + ;; Using an IPv6 address. (should (tramp-tramp-file-p "/[::1]:")) (should (tramp-tramp-file-p "/user@[::1]:")) @@ -426,6 +438,10 @@ is greater than 10. (should (tramp-tramp-file-p "/[::ffff:1.2.3.4]:")) (should (tramp-tramp-file-p "/user@[::ffff:1.2.3.4]:")) + ;; Using an IPv6 address with port. + (should (tramp-tramp-file-p "/[::1]#1234:")) + (should (tramp-tramp-file-p "/user@[::1]#1234:")) + ;; Local file name part. (should (tramp-tramp-file-p "/host::")) (should (tramp-tramp-file-p "/host:/:")) @@ -472,6 +488,10 @@ is greater than 10. (should (tramp-tramp-file-p "/[method/1.2.3.4]")) (should (tramp-tramp-file-p "/[method/user@1.2.3.4]")) + ;; Using an IPv4 address with port. + (should (tramp-tramp-file-p "/[method/1.2.3.4#1234]")) + (should (tramp-tramp-file-p "/[method/user@1.2.3.4#1234]")) + ;; Using an IPv6 address. (should (tramp-tramp-file-p "/[method/::1]")) (should (tramp-tramp-file-p "/[method/user@::1]")) @@ -480,6 +500,10 @@ is greater than 10. (should (tramp-tramp-file-p "/[method/::ffff:1.2.3.4]")) (should (tramp-tramp-file-p "/[method/user@::ffff:1.2.3.4]")) + ;; Using an IPv6 address with port. + (should (tramp-tramp-file-p "/[method/::1#1234]")) + (should (tramp-tramp-file-p "/[method/user@::1#1234]")) + ;; Local file name part. (should (tramp-tramp-file-p "/[method/]")) (should (tramp-tramp-file-p "/[method/]/:")) -- 2.39.2