aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorTino Calancha2021-06-27 17:53:30 +0200
committerLars Ingebrigtsen2021-07-02 12:53:35 +0200
commit9eadcfdfe6f7b26ba44360db9f828fdbe7a78fe7 (patch)
tree802363ba30df135240fcfa6ced076923d6e5a21b
parentc3322729e4eb04539e2b6b9b06088e131c6a84f0 (diff)
downloademacs-9eadcfdfe6f7b26ba44360db9f828fdbe7a78fe7.tar.gz
emacs-9eadcfdfe6f7b26ba44360db9f828fdbe7a78fe7.zip
lisp/auth-source-pass.el: Keep legitimate spaces inside data
Users should be able to store a field as follows: message: remember: Destroy the image and you will break the enemy and later, recover the message untouched, i.e.: "remember: Destroy the image and you will break the enemy" * lisp/auth-source-pass.el (auth-source-pass--parse-data): Preserve inner spaces at data. * test/lisp/auth-source-pass-tests.el (auth-source-pass-parse-with-colons-in-data): Add test.
-rw-r--r--lisp/auth-source-pass.el12
-rw-r--r--test/lisp/auth-source-pass-tests.el6
2 files changed, 11 insertions, 7 deletions
diff --git a/lisp/auth-source-pass.el b/lisp/auth-source-pass.el
index c512c6fe4fa..914f8d2f1bf 100644
--- a/lisp/auth-source-pass.el
+++ b/lisp/auth-source-pass.el
@@ -167,15 +167,13 @@ The secret is the first line of CONTENTS."
167(defun auth-source-pass--parse-data (contents) 167(defun auth-source-pass--parse-data (contents)
168 "Parse the password-store data in the string CONTENTS and return an alist. 168 "Parse the password-store data in the string CONTENTS and return an alist.
169CONTENTS is the contents of a password-store formatted file." 169CONTENTS is the contents of a password-store formatted file."
170 (let ((lines (split-string contents "\n" t "[ \t]+"))) 170 (let ((lines (cdr (split-string contents "\n" t "[ \t]+"))))
171 (seq-remove #'null 171 (seq-remove #'null
172 (mapcar (lambda (line) 172 (mapcar (lambda (line)
173 (let ((pair (mapcar (lambda (s) (string-trim s)) 173 (when-let ((pos (seq-position line ?:)))
174 (split-string line ":")))) 174 (cons (string-trim (substring line 0 pos))
175 (when (> (length pair) 1) 175 (string-trim (substring line (1+ pos))))))
176 (cons (car pair) 176 lines))))
177 (mapconcat #'identity (cdr pair) ":")))))
178 (cdr lines)))))
179 177
180(defun auth-source-pass--do-debug (&rest msg) 178(defun auth-source-pass--do-debug (&rest msg)
181 "Call `auth-source-do-debug` with MSG and a prefix." 179 "Call `auth-source-do-debug` with MSG and a prefix."
diff --git a/test/lisp/auth-source-pass-tests.el b/test/lisp/auth-source-pass-tests.el
index a2f84f20e8e..d050ac5b695 100644
--- a/test/lisp/auth-source-pass-tests.el
+++ b/test/lisp/auth-source-pass-tests.el
@@ -49,6 +49,12 @@
49 '(("key1" . "val1") 49 '(("key1" . "val1")
50 ("key2" . "val2")))))) 50 ("key2" . "val2"))))))
51 51
52(ert-deftest auth-source-pass-parse-with-colons-in-data ()
53 (let ((content "pass\n--\nkey1 :val1\nkey2: please: keep my space after colon\n\n"))
54 (should (equal (auth-source-pass--parse-data content)
55 '(("key1" . "val1")
56 ("key2" . "please: keep my space after colon"))))))
57
52(defvar auth-source-pass--debug-log nil 58(defvar auth-source-pass--debug-log nil
53 "Contains a list of all messages passed to `auth-source-do-debug`.") 59 "Contains a list of all messages passed to `auth-source-do-debug`.")
54 60