diff options
| author | Michael Albinus | 2017-10-25 13:36:49 +0200 |
|---|---|---|
| committer | Michael Albinus | 2017-10-25 13:36:49 +0200 |
| commit | 761c630766abf5b59c9b8c8f6edde07b276ea4b4 (patch) | |
| tree | 33b27342de1423fa265d77b20aadb6e014343f38 | |
| parent | 628b65320953ff5333b332e9010c16941cba177f (diff) | |
| download | emacs-761c630766abf5b59c9b8c8f6edde07b276ea4b4.tar.gz emacs-761c630766abf5b59c9b8c8f6edde07b276ea4b4.zip | |
Fix Bug#28982
* admin/MAINTAINERS: Add test/lisp/url/url-tramp-tests.el.
* lisp/url/url-tramp.el (url-tramp-convert-url-to-tramp)
(url-tramp-convert-tramp-to-url): Adapt to recent Tramp changes.
* test/lisp/url/url-tramp-tests.el: New file. (Bug#28982)
| -rw-r--r-- | admin/MAINTAINERS | 1 | ||||
| -rw-r--r-- | lisp/url/url-tramp.el | 58 | ||||
| -rw-r--r-- | test/lisp/url/url-tramp-tests.el | 83 |
3 files changed, 117 insertions, 25 deletions
diff --git a/admin/MAINTAINERS b/admin/MAINTAINERS index c13cb552a78..753a676e81a 100644 --- a/admin/MAINTAINERS +++ b/admin/MAINTAINERS | |||
| @@ -62,6 +62,7 @@ Michael Albinus | |||
| 62 | lisp/url/url-tramp.el | 62 | lisp/url/url-tramp.el |
| 63 | doc/misc/tramp*.texi | 63 | doc/misc/tramp*.texi |
| 64 | test/lisp/net/tramp-tests.el | 64 | test/lisp/net/tramp-tests.el |
| 65 | test/lisp/url/url-tramp-tests.el | ||
| 65 | 66 | ||
| 66 | D-Bus | 67 | D-Bus |
| 67 | src/dbusbind.c | 68 | src/dbusbind.c |
diff --git a/lisp/url/url-tramp.el b/lisp/url/url-tramp.el index c28cf6c23a1..0b07bd0d1aa 100644 --- a/lisp/url/url-tramp.el +++ b/lisp/url/url-tramp.el | |||
| @@ -37,33 +37,41 @@ They must also be covered by `url-handler-regexp'." | |||
| 37 | :type '(repeat string)) | 37 | :type '(repeat string)) |
| 38 | 38 | ||
| 39 | (defun url-tramp-convert-url-to-tramp (url) | 39 | (defun url-tramp-convert-url-to-tramp (url) |
| 40 | "Convert URL to a Tramp file name." | 40 | "Convert URL to a Tramp file name. |
| 41 | (let ((obj (url-generic-parse-url (and (stringp url) url)))) | 41 | If URL contains a password, it will be added to the `password-data' cache. |
| 42 | (if (member (url-type obj) url-tramp-protocols) | 42 | In case URL is not convertable, nil is returned." |
| 43 | (progn | 43 | (let* ((obj (url-generic-parse-url (and (stringp url) url))) |
| 44 | (if (url-password obj) | 44 | (port |
| 45 | (password-cache-add | 45 | (and (natnump (url-portspec obj)) |
| 46 | (tramp-make-tramp-file-name | 46 | (number-to-string (url-portspec obj))))) |
| 47 | (url-type obj) (url-user obj) (url-host obj) "") | 47 | (when (member (url-type obj) url-tramp-protocols) |
| 48 | (url-password obj)) | 48 | (when (url-password obj) |
| 49 | (tramp-make-tramp-file-name | 49 | (password-cache-add |
| 50 | (url-type obj) (url-user obj) (url-host obj) (url-filename obj)))) | 50 | (tramp-make-tramp-file-name |
| 51 | url))) | 51 | (url-type obj) (url-user obj) nil |
| 52 | (url-host obj) port "") | ||
| 53 | (url-password obj))) | ||
| 54 | (tramp-make-tramp-file-name | ||
| 55 | (url-type obj) (url-user obj) nil | ||
| 56 | (url-host obj) port (url-filename obj))))) | ||
| 52 | 57 | ||
| 53 | (defun url-tramp-convert-tramp-to-url (file) | 58 | (defun url-tramp-convert-tramp-to-url (file) |
| 54 | "Convert FILE, a Tramp file name, to a URL." | 59 | "Convert FILE, a Tramp file name, to a URL. |
| 55 | (let ((obj (ignore-errors (tramp-dissect-file-name file)))) | 60 | In case FILE is not convertable, nil is returned." |
| 56 | (if (member (tramp-file-name-method obj) url-tramp-protocols) | 61 | (let* ((obj (ignore-errors (tramp-dissect-file-name file))) |
| 57 | (url-recreate-url | 62 | (port |
| 58 | (url-parse-make-urlobj | 63 | (and (stringp (tramp-file-name-port obj)) |
| 59 | (tramp-file-name-method obj) | 64 | (string-to-number (tramp-file-name-port obj))))) |
| 60 | (tramp-file-name-user obj) | 65 | (when (member (tramp-file-name-method obj) url-tramp-protocols) |
| 61 | nil ; password. | 66 | (url-recreate-url |
| 62 | (tramp-file-name-host obj) | 67 | (url-parse-make-urlobj |
| 63 | nil ; port. | 68 | (tramp-file-name-method obj) |
| 64 | (tramp-file-name-localname obj) | 69 | (tramp-file-name-user obj) |
| 65 | nil nil t)) ; target attributes fullness. | 70 | nil ; password. |
| 66 | file))) | 71 | (tramp-file-name-host obj) |
| 72 | port | ||
| 73 | (tramp-file-name-localname obj) | ||
| 74 | nil nil t))))) ; target attributes fullness. | ||
| 67 | 75 | ||
| 68 | ;;;###autoload | 76 | ;;;###autoload |
| 69 | (defun url-tramp-file-handler (operation &rest args) | 77 | (defun url-tramp-file-handler (operation &rest args) |
diff --git a/test/lisp/url/url-tramp-tests.el b/test/lisp/url/url-tramp-tests.el new file mode 100644 index 00000000000..9892cd78475 --- /dev/null +++ b/test/lisp/url/url-tramp-tests.el | |||
| @@ -0,0 +1,83 @@ | |||
| 1 | ;;; url-tramp-tests.el --- Test suite for Tramp / URL conversion. | ||
| 2 | |||
| 3 | ;; Copyright (C) 2017 Free Software Foundation, Inc. | ||
| 4 | |||
| 5 | ;; Author: Michael Albinus <michael.albinus@gmx> | ||
| 6 | |||
| 7 | ;; This file is part of GNU Emacs. | ||
| 8 | |||
| 9 | ;; GNU Emacs is free software: you can redistribute it and/or modify | ||
| 10 | ;; it under the terms of the GNU General Public License as published by | ||
| 11 | ;; the Free Software Foundation, either version 3 of the License, or | ||
| 12 | ;; (at your option) any later version. | ||
| 13 | |||
| 14 | ;; GNU Emacs is distributed in the hope that it will be useful, | ||
| 15 | ;; but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
| 16 | ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
| 17 | ;; GNU General Public License for more details. | ||
| 18 | |||
| 19 | ;; You should have received a copy of the GNU General Public License | ||
| 20 | ;; along with GNU Emacs. If not, see <https://www.gnu.org/licenses/>. | ||
| 21 | |||
| 22 | ;;; Code: | ||
| 23 | |||
| 24 | (require 'url-tramp) | ||
| 25 | (require 'ert) | ||
| 26 | |||
| 27 | (ert-deftest url-tramp-test-convert-url-to-tramp () | ||
| 28 | "Test that URLs are converted into proper Tramp file names." | ||
| 29 | (should | ||
| 30 | (string-equal | ||
| 31 | (url-tramp-convert-url-to-tramp "ftp://ftp.is.co.za/rfc/rfc1808.txt") | ||
| 32 | "/ftp:ftp.is.co.za:/rfc/rfc1808.txt")) | ||
| 33 | |||
| 34 | (should | ||
| 35 | (string-equal | ||
| 36 | (url-tramp-convert-url-to-tramp "ssh://user@localhost") | ||
| 37 | "/ssh:user@localhost:")) | ||
| 38 | |||
| 39 | (should | ||
| 40 | (string-equal | ||
| 41 | (url-tramp-convert-url-to-tramp "telnet://remotehost:42") | ||
| 42 | "/telnet:remotehost#42:")) | ||
| 43 | |||
| 44 | ;; The password will be added to the cache. The password cache key | ||
| 45 | ;; is the remote file name identification of the Tramp file. | ||
| 46 | (should | ||
| 47 | (string-equal | ||
| 48 | (url-tramp-convert-url-to-tramp "scp://user:geheim@somewhere/localfile") | ||
| 49 | "/scp:user@somewhere:/localfile")) | ||
| 50 | (let ((key | ||
| 51 | (file-remote-p | ||
| 52 | (url-tramp-convert-url-to-tramp "scp://user@somewhere/localfile")))) | ||
| 53 | (should (password-in-cache-p key)) | ||
| 54 | (should (string-equal (password-read-from-cache key) "geheim")) | ||
| 55 | (password-cache-remove key) | ||
| 56 | (should-not (password-in-cache-p key))) | ||
| 57 | |||
| 58 | ;; "http" does not belong to `url-tramp-protocols'. | ||
| 59 | (should-not (url-tramp-convert-url-to-tramp "http://www.gnu.org"))) | ||
| 60 | |||
| 61 | (ert-deftest url-tramp-test-convert-tramp-to-url () | ||
| 62 | "Test that Tramp file names are converted into proper URLs." | ||
| 63 | (should | ||
| 64 | (string-equal | ||
| 65 | (url-tramp-convert-tramp-to-url "/ftp:ftp.is.co.za:/rfc/rfc1808.txt") | ||
| 66 | "ftp://ftp.is.co.za/rfc/rfc1808.txt")) | ||
| 67 | |||
| 68 | (should | ||
| 69 | (string-equal | ||
| 70 | (url-tramp-convert-tramp-to-url "/ssh:user@localhost:") | ||
| 71 | "ssh://user@localhost")) | ||
| 72 | |||
| 73 | (should | ||
| 74 | (string-equal | ||
| 75 | (url-tramp-convert-tramp-to-url "/telnet:user@remotehost#42:") | ||
| 76 | "telnet://user@remotehost:42")) | ||
| 77 | |||
| 78 | ;; "sftp" does not belong to `url-tramp-protocols'. | ||
| 79 | (should-not (url-tramp-convert-tramp-to-url "/sftp:user@localhost:"))) | ||
| 80 | |||
| 81 | (provide 'url-tramp-tests) | ||
| 82 | |||
| 83 | ;;; url-tramp-tests.el ends here | ||