From 454090fe40bec3b62e6fd7faa91fd18750705bbb Mon Sep 17 00:00:00 2001 From: James McCoy Date: Sun, 18 Sep 2016 15:22:06 -0400 Subject: [PATCH] GPGEncrypt: Remove (file)encoding dance around file encryption Changing &encoding when &fileencoding != &encoding causes two problems. First, it's completely unsafe to change &encoding after vim is running, since there may be characters that can't be translated from one encoding to another, which can make vim crash. Second, this actually loses information about the buffer's encoding. When the encrypted file is opened later, it won't be in the same encoding as before it was saved. Changing user's data on them is unacceptable. Signed-off-by: James McCoy --- plugin/gnupg.vim | 16 ---------------- 1 file changed, 16 deletions(-) diff --git a/plugin/gnupg.vim b/plugin/gnupg.vim index e02c71c..4bb3b9a 100644 --- a/plugin/gnupg.vim +++ b/plugin/gnupg.vim @@ -644,16 +644,6 @@ function s:GPGEncrypt() silent exe ':doautocmd '. auType .'Pre '. autocmd_filename call s:GPGDebug(2, 'called '. auType .'Pre autocommand for ' . autocmd_filename) - " store encoding and switch to a safe one - if (&fileencoding != &encoding) - let s:GPGEncoding = &encoding - let &encoding = &fileencoding - call s:GPGDebug(2, "encoding was \"" . s:GPGEncoding . "\", switched to \"" . &encoding . "\"") - else - let s:GPGEncoding = "" - call s:GPGDebug(2, "encoding and fileencoding are the same (\"" . &encoding . "\"), not switching") - endif - " guard for unencrypted files if (exists("b:GPGEncrypted") && b:GPGEncrypted == 0) echohl GPGError @@ -719,12 +709,6 @@ function s:GPGEncrypt() let cmd.redirect = '>' . s:shellescape(destfile, 1) silent call s:GPGExecute(cmd) - " restore encoding - if (s:GPGEncoding != "") - let &encoding = s:GPGEncoding - call s:GPGDebug(2, "restored encoding \"" . &encoding . "\"") - endif - if (v:shell_error) " message could not be encrypted " Command failed, so clean up the tempfile call delete(destfile)