[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
parsing bugs in auth-source
From: |
Filipp Gunbin |
Subject: |
parsing bugs in auth-source |
Date: |
Tue, 15 May 2018 03:09:29 +0300 |
Hello,
Could you please review the attached patch? It fixes two things in
auth-source which I believe are bugs.
Thanks,
Filipp.
>From af2719c4a247134597f9641e069dae3e5a0877ba Mon Sep 17 00:00:00 2001
From: Filipp Gunbin <address@hidden>
Date: Tue, 15 May 2018 03:02:49 +0300
Subject: [PATCH] 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.
---
lisp/auth-source.el | 12 +++++++-----
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 8b54c8118d..fb2cc8c49f 100644
--- a/lisp/auth-source.el
+++ b/lisp/auth-source.el
@@ -1000,12 +1000,13 @@ auth-source--aget
(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."
@@ -1015,8 +1016,9 @@ auth-source-netrc-parse-one
(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)
diff --git a/test/lisp/auth-source-tests.el b/test/lisp/auth-source-tests.el
index 2f5a9320b1..97a575d8ee 100644
--- a/test/lisp/auth-source-tests.el
+++ b/test/lisp/auth-source-tests.el
@@ -208,6 +208,25 @@ auth-source--test-netrc-parse-entry
("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")))
--
2.12.2
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- parsing bugs in auth-source,
Filipp Gunbin <=