From: Eli Zaretskii Date: Thu, 17 Dec 2015 18:31:25 +0000 (+0200) Subject: Fix parsing netrc entries with ports X-Git-Tag: emacs-25.0.90~453 X-Git-Url: http://git.eshelyaron.com/gitweb/?a=commitdiff_plain;h=938495317a02b06a6c512832d0c6d9530fcd7f2b;p=emacs.git Fix parsing netrc entries with ports * lisp/gnus/auth-source.el (auth-source-ensure-strings): Don't make a list out of 't'. (Bug#22188) * test/automated/auth-source-tests.el (auth-source-test-netrc-parse-entry): New test. --- diff --git a/lisp/gnus/auth-source.el b/lisp/gnus/auth-source.el index 9d842c04f64..10d32d45070 100644 --- a/lisp/gnus/auth-source.el +++ b/lisp/gnus/auth-source.el @@ -919,13 +919,15 @@ while \(:host t) would find all host entries." prompt) (defun auth-source-ensure-strings (values) - (unless (listp values) - (setq values (list values))) - (mapcar (lambda (value) - (if (numberp value) - (format "%s" value) - value)) - values)) + (if (eq values t) + values + (unless (listp values) + (setq values (list values))) + (mapcar (lambda (value) + (if (numberp value) + (format "%s" value) + value)) + values))) ;;; Backend specific parsing: netrc/authinfo backend diff --git a/test/automated/auth-source-tests.el b/test/automated/auth-source-tests.el index 0b49b9013f7..dd70d546d5c 100644 --- a/test/automated/auth-source-tests.el +++ b/test/automated/auth-source-tests.el @@ -174,5 +174,50 @@ (:search-function . auth-source-secrets-search) (:create-function . auth-source-secrets-create))))) +(defun auth-source--test-netrc-parse-entry (entry host user port) + "Parse a netrc entry from buffer." + (auth-source-forget-all-cached) + (setq port (auth-source-ensure-strings port)) + (with-temp-buffer + (insert entry) + (goto-char (point-min)) + (let* ((check (lambda(alist) + (and alist + (auth-source-search-collection + host + (or + (auth-source--aget alist "machine") + (auth-source--aget alist "host") + t)) + (auth-source-search-collection + user + (or + (auth-source--aget alist "login") + (auth-source--aget alist "account") + (auth-source--aget alist "user") + t)) + (auth-source-search-collection + port + (or + (auth-source--aget alist "port") + (auth-source--aget alist "protocol") + t))))) + (entries (auth-source-netrc-parse-entries check 1))) + entries))) + +(ert-deftest auth-source-test-netrc-parse-entry () + (should (equal (auth-source--test-netrc-parse-entry + "machine mymachine1 login user1 password pass1\n" t t t) + '((("password" . "pass1") + ("login" . "user1") + ("machine" . "mymachine1"))))) + (should (equal (auth-source--test-netrc-parse-entry + "machine mymachine1 login user1 password pass1 port 100\n" + t t t) + '((("port" . "100") + ("password" . "pass1") + ("login" . "user1") + ("machine" . "mymachine1")))))) + (provide 'auth-source-tests) ;;; auth-source-tests.el ends here