aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorFilipp Gunbin2018-05-15 03:02:49 +0300
committerNoam Postavsky2018-08-10 08:36:24 -0400
commit5e42c349a0533602c23bf651d6b28eca25e95a46 (patch)
tree3b73ef3bcd510e0201e65980343d9f92bd7dd64c
parent71c92d89137b7fdde6c2bd4bed9b8dfda5fa53dd (diff)
downloademacs-5e42c349a0533602c23bf651d6b28eca25e95a46.tar.gz
emacs-5e42c349a0533602c23bf651d6b28eca25e95a46.zip
Fix bugs in `auth-source-netrc-parse-one'.
* lisp/auth-source.el (auth-source-netrc-parse-one): Ensure that match data is not overwritten in `auth-source-netrc-parse-next-interesting'. Ensure that blanks are skipped before and after going over comments and eols. * test/lisp/auth-source-tests.el (auth-source-test-netrc-parse-one): New test. (cherry picked from commit 60ff8101449eea3a5ca4961299501efd83d011bd)
-rw-r--r--lisp/auth-source.el12
-rw-r--r--test/lisp/auth-source-tests.el19
2 files changed, 26 insertions, 5 deletions
diff --git a/lisp/auth-source.el b/lisp/auth-source.el
index 374b7f1e86c..afb35c8f044 100644
--- a/lisp/auth-source.el
+++ b/lisp/auth-source.el
@@ -984,12 +984,13 @@ Note that the MAX parameter is used so we can exit the parse early."
984 984
985(defun auth-source-netrc-parse-next-interesting () 985(defun auth-source-netrc-parse-next-interesting ()
986 "Advance to the next interesting position in the current buffer." 986 "Advance to the next interesting position in the current buffer."
987 (skip-chars-forward "\t ")
987 ;; If we're looking at a comment or are at the end of the line, move forward 988 ;; If we're looking at a comment or are at the end of the line, move forward
988 (while (or (looking-at "#") 989 (while (or (eq (char-after) ?#)
989 (and (eolp) 990 (and (eolp)
990 (not (eobp)))) 991 (not (eobp))))
991 (forward-line 1)) 992 (forward-line 1)
992 (skip-chars-forward "\t ")) 993 (skip-chars-forward "\t ")))
993 994
994(defun auth-source-netrc-parse-one () 995(defun auth-source-netrc-parse-one ()
995 "Read one thing from the current buffer." 996 "Read one thing from the current buffer."
@@ -999,8 +1000,9 @@ Note that the MAX parameter is used so we can exit the parse early."
999 (looking-at "\"\\([^\"]*\\)\"") 1000 (looking-at "\"\\([^\"]*\\)\"")
1000 (looking-at "\\([^ \t\n]+\\)")) 1001 (looking-at "\\([^ \t\n]+\\)"))
1001 (forward-char (length (match-string 0))) 1002 (forward-char (length (match-string 0)))
1002 (auth-source-netrc-parse-next-interesting) 1003 (prog1
1003 (match-string-no-properties 1))) 1004 (match-string-no-properties 1)
1005 (auth-source-netrc-parse-next-interesting))))
1004 1006
1005;; with thanks to org-mode 1007;; with thanks to org-mode
1006(defsubst auth-source-current-line (&optional pos) 1008(defsubst auth-source-current-line (&optional pos)
diff --git a/test/lisp/auth-source-tests.el b/test/lisp/auth-source-tests.el
index c1ee9093744..90caac8e4a2 100644
--- a/test/lisp/auth-source-tests.el
+++ b/test/lisp/auth-source-tests.el
@@ -210,6 +210,25 @@
210 ("login" . "user1") 210 ("login" . "user1")
211 ("machine" . "mymachine1")))))) 211 ("machine" . "mymachine1"))))))
212 212
213(ert-deftest auth-source-test-netrc-parse-one ()
214 (should (equal (auth-source--test-netrc-parse-one--all
215 "machine host1\n# comment\n")
216 '("machine" "host1")))
217 (should (equal (auth-source--test-netrc-parse-one--all
218 "machine host1\n \n \nmachine host2\n")
219 '("machine" "host1" "machine" "host2"))))
220
221(defun auth-source--test-netrc-parse-one--all (text)
222 "Parse TEXT with `auth-source-netrc-parse-one' until end,return list."
223 (with-temp-buffer
224 (insert text)
225 (goto-char (point-min))
226 (let ((one (auth-source-netrc-parse-one)) all)
227 (while one
228 (push one all)
229 (setq one (auth-source-netrc-parse-one)))
230 (nreverse all))))
231
213(ert-deftest auth-source-test-format-prompt () 232(ert-deftest auth-source-test-format-prompt ()
214 (should (equal (auth-source-format-prompt "test %u %h %p" '((?u "user") (?h "host"))) 233 (should (equal (auth-source-format-prompt "test %u %h %p" '((?u "user") (?h "host")))
215 "test user host %p"))) 234 "test user host %p")))