]> git.eshelyaron.com Git - emacs.git/commitdiff
Fix Tramp parser
authorMichael Albinus <michael.albinus@gmx.de>
Sun, 7 Jul 2024 17:34:37 +0000 (19:34 +0200)
committerEshel Yaron <me@eshelyaron.com>
Mon, 8 Jul 2024 20:57:57 +0000 (22:57 +0200)
* 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
test/lisp/net/tramp-tests.el

index 53f1af50878859e43fd180cac5608e766511f864..8b86a2aab4d604f3faadba597e062d8b5e7eb751 100644 (file)
@@ -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 "|"
index d51286d205324b67b8926ac2d9be121f4dde148c..ece3fa17f54c2e847aa1d9b8d4b2324313acf6de 100644 (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: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/]/:"))