mirror of
https://git.savannah.gnu.org/git/emacs.git
synced 2024-11-21 06:55:39 +00:00
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.
This commit is contained in:
parent
c3322729e4
commit
9eadcfdfe6
@ -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."
|
||||
|
@ -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`.")
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user