[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
master 9eadcfd 5/5: lisp/auth-source-pass.el: Keep legitimate spaces ins
From: |
Lars Ingebrigtsen |
Subject: |
master 9eadcfd 5/5: lisp/auth-source-pass.el: Keep legitimate spaces inside data |
Date: |
Fri, 2 Jul 2021 06:53:44 -0400 (EDT) |
branch: master
commit 9eadcfdfe6f7b26ba44360db9f828fdbe7a78fe7
Author: Tino Calancha <tino.calancha@gmail.com>
Commit: Lars Ingebrigtsen <larsi@gnus.org>
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.
---
lisp/auth-source-pass.el | 12 +++++-------
test/lisp/auth-source-pass-tests.el | 6 ++++++
2 files changed, 11 insertions(+), 7 deletions(-)
diff --git a/lisp/auth-source-pass.el b/lisp/auth-source-pass.el
index c512c6f..914f8d2 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."
(defun auth-source-pass--parse-data (contents)
"Parse the password-store data in the string CONTENTS and return an alist.
CONTENTS is the contents of a password-store formatted file."
- (let ((lines (split-string contents "\n" t "[ \t]+")))
+ (let ((lines (cdr (split-string contents "\n" t "[ \t]+"))))
(seq-remove #'null
(mapcar (lambda (line)
- (let ((pair (mapcar (lambda (s) (string-trim s))
- (split-string line ":"))))
- (when (> (length pair) 1)
- (cons (car pair)
- (mapconcat #'identity (cdr pair) ":")))))
- (cdr lines)))))
+ (when-let ((pos (seq-position line ?:)))
+ (cons (string-trim (substring line 0 pos))
+ (string-trim (substring line (1+ pos))))))
+ lines))))
(defun auth-source-pass--do-debug (&rest msg)
"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 a2f84f2..d050ac5 100644
--- a/test/lisp/auth-source-pass-tests.el
+++ b/test/lisp/auth-source-pass-tests.el
@@ -49,6 +49,12 @@
'(("key1" . "val1")
("key2" . "val2"))))))
+(ert-deftest auth-source-pass-parse-with-colons-in-data ()
+ (let ((content "pass\n--\nkey1 :val1\nkey2: please: keep my space after
colon\n\n"))
+ (should (equal (auth-source-pass--parse-data content)
+ '(("key1" . "val1")
+ ("key2" . "please: keep my space after colon"))))))
+
(defvar auth-source-pass--debug-log nil
"Contains a list of all messages passed to `auth-source-do-debug`.")