[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
emacs-30 f4c0459ed3e 1/2: Fix Tramp parser
From: |
Michael Albinus |
Subject: |
emacs-30 f4c0459ed3e 1/2: Fix Tramp parser |
Date: |
Sun, 7 Jul 2024 13:35:24 -0400 (EDT) |
branch: emacs-30
commit f4c0459ed3edce33329744f60a0e389c20dc60a5
Author: Michael Albinus <michael.albinus@gmx.de>
Commit: Michael Albinus <michael.albinus@gmx.de>
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.
---
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 f97ed66c58b..abde62d4371 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 bf77179e039..8074bed7a47 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/]/:"))