From aeda13cfdf80b64c48313cbe6abd2ff028431808 Mon Sep 17 00:00:00 2001 From: ckelsel Date: Fri, 7 Sep 2018 20:38:25 +0800 Subject: 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) https://github.com/vim/vim/commit/e6bf655bc4de1b7f4586e1f5c2fc4978141c3aa3 --- src/nvim/testdir/test_writefile.vim | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) (limited to 'src/nvim/testdir/test_writefile.vim') diff --git a/src/nvim/testdir/test_writefile.vim b/src/nvim/testdir/test_writefile.vim index 06f9d03554..1cd5fb306a 100644 --- a/src/nvim/testdir/test_writefile.vim +++ b/src/nvim/testdir/test_writefile.vim @@ -32,6 +32,24 @@ 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 + func SetFlag(timer) let g:flag = 1 endfunc -- cgit