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 <jamessan@jamessan.com>
This commit is contained in:
parent
22cca0c821
commit
454090fe40
@ -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)
|
||||
|
Loading…
Reference in New Issue
Block a user