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.
This commit is contained in:
Michael Albinus 2024-07-07 19:34:37 +02:00
parent 47c79b62dd
commit f4c0459ed3
2 changed files with 40 additions and 5 deletions

View file

@ -78,6 +78,7 @@
(defvar tramp-postfix-ipv6-regexp) (defvar tramp-postfix-ipv6-regexp)
(defvar tramp-postfix-host-format) (defvar tramp-postfix-host-format)
(defvar tramp-postfix-host-regexp) (defvar tramp-postfix-host-regexp)
(defvar tramp-host-with-port-regexp)
(defvar tramp-remote-file-name-spec-regexp) (defvar tramp-remote-file-name-spec-regexp)
(defvar tramp-file-name-structure) (defvar tramp-file-name-structure)
(defvar tramp-file-name-regexp) (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-ipv6-regexp (tramp-build-postfix-ipv6-regexp)
tramp-postfix-host-format (tramp-build-postfix-host-format) tramp-postfix-host-format (tramp-build-postfix-host-format)
tramp-postfix-host-regexp (tramp-build-postfix-host-regexp) 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-remote-file-name-spec-regexp
(tramp-build-remote-file-name-spec-regexp) (tramp-build-remote-file-name-spec-regexp)
tramp-file-name-structure (tramp-build-file-name-structure) 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'." "Return `tramp-postfix-method-format' according to `tramp-syntax'."
(tramp-lookup-syntax tramp-postfix-method-format-alist)) (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. "String matching delimiter between method and user or host names.
The `ftp' syntax does not support methods. The `ftp' syntax does not support methods.
Used in `tramp-make-tramp-file-name'.") Used in `tramp-make-tramp-file-name'.")
@ -964,7 +967,8 @@ Used in `tramp-make-tramp-file-name'.")
"Return `tramp-postfix-method-regexp'." "Return `tramp-postfix-method-regexp'."
(rx (literal (tramp-build-postfix-method-format)))) (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. "Regexp matching delimiter between method and user or host names.
Derived from `tramp-postfix-method-format'.") Derived from `tramp-postfix-method-format'.")
@ -1059,11 +1063,18 @@ Derived from `tramp-prefix-port-format'.")
(defconst tramp-port-regexp (rx (+ digit)) (defconst tramp-port-regexp (rx (+ digit))
"Regexp matching port numbers.") "Regexp matching port numbers.")
(defconst tramp-host-with-port-regexp (defun tramp-build-host-with-port-regexp ()
"Return `tramp-host-with-port-regexp'."
(rx (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) (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.") "Regexp matching host names with port numbers.")
(defconst tramp-postfix-hop-format "|" (defconst tramp-postfix-hop-format "|"

View file

@ -330,6 +330,10 @@ is greater than 10.
(should (tramp-tramp-file-p "/method:1.2.3.4:")) (should (tramp-tramp-file-p "/method:1.2.3.4:"))
(should (tramp-tramp-file-p "/method:user@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. ;; Using an IPv6 address.
(should (tramp-tramp-file-p "/method:[::1]:")) (should (tramp-tramp-file-p "/method:[::1]:"))
(should (tramp-tramp-file-p "/method:user@[::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:[::ffff:1.2.3.4]:"))
(should (tramp-tramp-file-p "/method:user@[::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. ;; Local file name part.
(should (tramp-tramp-file-p "/method:::")) (should (tramp-tramp-file-p "/method:::"))
(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 "/1.2.3.4:"))
(should (tramp-tramp-file-p "/user@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. ;; Using an IPv6 address.
(should (tramp-tramp-file-p "/[::1]:")) (should (tramp-tramp-file-p "/[::1]:"))
(should (tramp-tramp-file-p "/user@[::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 "/[::ffff:1.2.3.4]:"))
(should (tramp-tramp-file-p "/user@[::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. ;; Local file name part.
(should (tramp-tramp-file-p "/host::")) (should (tramp-tramp-file-p "/host::"))
(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/1.2.3.4]"))
(should (tramp-tramp-file-p "/[method/user@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. ;; Using an IPv6 address.
(should (tramp-tramp-file-p "/[method/::1]")) (should (tramp-tramp-file-p "/[method/::1]"))
(should (tramp-tramp-file-p "/[method/user@::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/::ffff:1.2.3.4]"))
(should (tramp-tramp-file-p "/[method/user@::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. ;; Local file name part.
(should (tramp-tramp-file-p "/[method/]")) (should (tramp-tramp-file-p "/[method/]"))
(should (tramp-tramp-file-p "/[method/]/:")) (should (tramp-tramp-file-p "/[method/]/:"))