mirror of
https://git.savannah.gnu.org/git/emacs.git
synced 2024-12-27 10:54:40 +00:00
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 60ff810144
)
This commit is contained in:
parent
71c92d8913
commit
5e42c349a0
@ -984,12 +984,13 @@ Note that the MAX parameter is used so we can exit the parse early."
|
||||
|
||||
(defun auth-source-netrc-parse-next-interesting ()
|
||||
"Advance to the next interesting position in the current buffer."
|
||||
(skip-chars-forward "\t ")
|
||||
;; If we're looking at a comment or are at the end of the line, move forward
|
||||
(while (or (looking-at "#")
|
||||
(while (or (eq (char-after) ?#)
|
||||
(and (eolp)
|
||||
(not (eobp))))
|
||||
(forward-line 1))
|
||||
(skip-chars-forward "\t "))
|
||||
(forward-line 1)
|
||||
(skip-chars-forward "\t ")))
|
||||
|
||||
(defun auth-source-netrc-parse-one ()
|
||||
"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."
|
||||
(looking-at "\"\\([^\"]*\\)\"")
|
||||
(looking-at "\\([^ \t\n]+\\)"))
|
||||
(forward-char (length (match-string 0)))
|
||||
(auth-source-netrc-parse-next-interesting)
|
||||
(match-string-no-properties 1)))
|
||||
(prog1
|
||||
(match-string-no-properties 1)
|
||||
(auth-source-netrc-parse-next-interesting))))
|
||||
|
||||
;; with thanks to org-mode
|
||||
(defsubst auth-source-current-line (&optional pos)
|
||||
|
@ -210,6 +210,25 @@
|
||||
("login" . "user1")
|
||||
("machine" . "mymachine1"))))))
|
||||
|
||||
(ert-deftest auth-source-test-netrc-parse-one ()
|
||||
(should (equal (auth-source--test-netrc-parse-one--all
|
||||
"machine host1\n# comment\n")
|
||||
'("machine" "host1")))
|
||||
(should (equal (auth-source--test-netrc-parse-one--all
|
||||
"machine host1\n \n \nmachine host2\n")
|
||||
'("machine" "host1" "machine" "host2"))))
|
||||
|
||||
(defun auth-source--test-netrc-parse-one--all (text)
|
||||
"Parse TEXT with `auth-source-netrc-parse-one' until end,return list."
|
||||
(with-temp-buffer
|
||||
(insert text)
|
||||
(goto-char (point-min))
|
||||
(let ((one (auth-source-netrc-parse-one)) all)
|
||||
(while one
|
||||
(push one all)
|
||||
(setq one (auth-source-netrc-parse-one)))
|
||||
(nreverse all))))
|
||||
|
||||
(ert-deftest auth-source-test-format-prompt ()
|
||||
(should (equal (auth-source-format-prompt "test %u %h %p" '((?u "user") (?h "host")))
|
||||
"test user host %p")))
|
||||
|
Loading…
Reference in New Issue
Block a user