diff options
| author | Filipp Gunbin | 2018-05-15 03:02:49 +0300 |
|---|---|---|
| committer | Filipp Gunbin | 2018-05-17 18:44:31 +0300 |
| commit | 60ff8101449eea3a5ca4961299501efd83d011bd (patch) | |
| tree | 9947d1ac9503a65842975bb560a78265c41bc9a9 | |
| parent | 01120ec3d2eecd11e23f008feed020def7ea0e88 (diff) | |
| download | emacs-60ff8101449eea3a5ca4961299501efd83d011bd.tar.gz emacs-60ff8101449eea3a5ca4961299501efd83d011bd.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.
| -rw-r--r-- | lisp/auth-source.el | 12 | ||||
| -rw-r--r-- | test/lisp/auth-source-tests.el | 19 |
2 files changed, 26 insertions, 5 deletions
diff --git a/lisp/auth-source.el b/lisp/auth-source.el index 918d785eaef..abff0def95f 100644 --- a/lisp/auth-source.el +++ b/lisp/auth-source.el | |||
| @@ -1000,12 +1000,13 @@ Note that the MAX parameter is used so we can exit the parse early." | |||
| 1000 | 1000 | ||
| 1001 | (defun auth-source-netrc-parse-next-interesting () | 1001 | (defun auth-source-netrc-parse-next-interesting () |
| 1002 | "Advance to the next interesting position in the current buffer." | 1002 | "Advance to the next interesting position in the current buffer." |
| 1003 | (skip-chars-forward "\t ") | ||
| 1003 | ;; If we're looking at a comment or are at the end of the line, move forward | 1004 | ;; If we're looking at a comment or are at the end of the line, move forward |
| 1004 | (while (or (looking-at "#") | 1005 | (while (or (eq (char-after) ?#) |
| 1005 | (and (eolp) | 1006 | (and (eolp) |
| 1006 | (not (eobp)))) | 1007 | (not (eobp)))) |
| 1007 | (forward-line 1)) | 1008 | (forward-line 1) |
| 1008 | (skip-chars-forward "\t ")) | 1009 | (skip-chars-forward "\t "))) |
| 1009 | 1010 | ||
| 1010 | (defun auth-source-netrc-parse-one () | 1011 | (defun auth-source-netrc-parse-one () |
| 1011 | "Read one thing from the current buffer." | 1012 | "Read one thing from the current buffer." |
| @@ -1015,8 +1016,9 @@ Note that the MAX parameter is used so we can exit the parse early." | |||
| 1015 | (looking-at "\"\\([^\"]*\\)\"") | 1016 | (looking-at "\"\\([^\"]*\\)\"") |
| 1016 | (looking-at "\\([^ \t\n]+\\)")) | 1017 | (looking-at "\\([^ \t\n]+\\)")) |
| 1017 | (forward-char (length (match-string 0))) | 1018 | (forward-char (length (match-string 0))) |
| 1018 | (auth-source-netrc-parse-next-interesting) | 1019 | (prog1 |
| 1019 | (match-string-no-properties 1))) | 1020 | (match-string-no-properties 1) |
| 1021 | (auth-source-netrc-parse-next-interesting)))) | ||
| 1020 | 1022 | ||
| 1021 | ;; with thanks to org-mode | 1023 | ;; with thanks to org-mode |
| 1022 | (defsubst auth-source-current-line (&optional pos) | 1024 | (defsubst auth-source-current-line (&optional pos) |
diff --git a/test/lisp/auth-source-tests.el b/test/lisp/auth-source-tests.el index 1f6737cb7c8..be516f2c40d 100644 --- a/test/lisp/auth-source-tests.el +++ b/test/lisp/auth-source-tests.el | |||
| @@ -208,6 +208,25 @@ | |||
| 208 | ("login" . "user1") | 208 | ("login" . "user1") |
| 209 | ("machine" . "mymachine1")))))) | 209 | ("machine" . "mymachine1")))))) |
| 210 | 210 | ||
| 211 | (ert-deftest auth-source-test-netrc-parse-one () | ||
| 212 | (should (equal (auth-source--test-netrc-parse-one--all | ||
| 213 | "machine host1\n# comment\n") | ||
| 214 | '("machine" "host1"))) | ||
| 215 | (should (equal (auth-source--test-netrc-parse-one--all | ||
| 216 | "machine host1\n \n \nmachine host2\n") | ||
| 217 | '("machine" "host1" "machine" "host2")))) | ||
| 218 | |||
| 219 | (defun auth-source--test-netrc-parse-one--all (text) | ||
| 220 | "Parse TEXT with `auth-source-netrc-parse-one' until end,return list." | ||
| 221 | (with-temp-buffer | ||
| 222 | (insert text) | ||
| 223 | (goto-char (point-min)) | ||
| 224 | (let ((one (auth-source-netrc-parse-one)) all) | ||
| 225 | (while one | ||
| 226 | (push one all) | ||
| 227 | (setq one (auth-source-netrc-parse-one))) | ||
| 228 | (nreverse all)))) | ||
| 229 | |||
| 211 | (ert-deftest auth-source-test-format-prompt () | 230 | (ert-deftest auth-source-test-format-prompt () |
| 212 | (should (equal (auth-source-format-prompt "test %u %h %p" '((?u "user") (?h "host"))) | 231 | (should (equal (auth-source-format-prompt "test %u %h %p" '((?u "user") (?h "host"))) |
| 213 | "test user host %p"))) | 232 | "test user host %p"))) |