From dd727cf0cb5319521f71d389a39dc3def541b2ef Mon Sep 17 00:00:00 2001 From: Nicolas Goaziou Date: Sun, 1 Jan 2017 10:26:22 +0100 Subject: [PATCH] org-crypt: Fix data loss when providing an empty key * lisp/org-crypt.el (org-encrypt-entry): Insert original text back upon encryption failure. Reported-by: fxiny --- lisp/org-crypt.el | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/lisp/org-crypt.el b/lisp/org-crypt.el index 103999624..412aeafda 100644 --- a/lisp/org-crypt.el +++ b/lisp/org-crypt.el @@ -183,7 +183,11 @@ See `org-crypt-disable-auto-save'." (org-end-of-subtree t t) (org-back-over-empty-lines) (let ((contents (delete-and-extract-region beg (point)))) - (insert (org-encrypt-string contents crypt-key))) + (condition-case err + (insert (org-encrypt-string contents crypt-key)) + ;; If encryption failed, make sure to insert back entry + ;; contents in the buffer. + (error (insert contents) (error (nth 1 err))))) (when folded (goto-char start-heading) (outline-hide-subtree)) -- 2.11.4.GIT