forked from aniani/vim
patch 8.0.0685: when conversion fails written file may be truncated
Problem: When making backups is disabled and conversion with iconv fails
the written file is truncated. (Luo Chen)
Solution: First try converting the file and write the file only when it did
not fail. (partly by Christian Brabandt)
This commit is contained in:
@@ -31,3 +31,21 @@ func Test_writefile_fails_gently()
|
||||
|
||||
call assert_fails('call writefile([], [])', 'E730:')
|
||||
endfunc
|
||||
|
||||
func Test_writefile_fails_conversion()
|
||||
if !has('multi_byte') || !has('iconv')
|
||||
return
|
||||
endif
|
||||
set nobackup nowritebackup
|
||||
new
|
||||
let contents = ["line one", "line two"]
|
||||
call writefile(contents, 'Xfile')
|
||||
edit Xfile
|
||||
call setline(1, ["first line", "cannot convert \u010b", "third line"])
|
||||
call assert_fails('write ++enc=cp932')
|
||||
call assert_equal(contents, readfile('Xfile'))
|
||||
|
||||
call delete('Xfile')
|
||||
bwipe!
|
||||
set backup& writebackup&
|
||||
endfunc
|
||||
|
||||
Reference in New Issue
Block a user