]> granicus.if.org Git - vim/commitdiff
patch 8.2.2199: first write after setting 'eol' does not have NL added v8.2.2199
authorBram Moolenaar <Bram@vim.org>
Wed, 23 Dec 2020 17:54:57 +0000 (18:54 +0100)
committerBram Moolenaar <Bram@vim.org>
Wed, 23 Dec 2020 17:54:57 +0000 (18:54 +0100)
Problem:    First write after setting 'eol' does not have NL added. (Tomáš
            Janoušek)
Solution:   Only use b_no_eol_lnum when doing a binary write. (closes #7535)

src/bufwrite.c
src/testdir/test_writefile.vim
src/version.c

index c6d882cd5fb6f086a91824f19290ff6a6f953134..d7c74de35c315cbaeddaa88e42ef2db0478771fa 100644 (file)
@@ -2031,7 +2031,7 @@ restore_backup:
            if (end == 0
                    || (lnum == end
                        && (write_bin || !buf->b_p_fixeol)
-                       && (lnum == buf->b_no_eol_lnum
+                       && ((write_bin && lnum == buf->b_no_eol_lnum)
                            || (lnum == buf->b_ml.ml_line_count
                                                           && !buf->b_p_eol))))
            {
index c858b7521ac6dc8606393d34fbb4507f66fa2bb6..f42ec14bb17168446fbdadcff9a476f8285dba61 100644 (file)
@@ -676,4 +676,22 @@ func Test_readwrite_file_with_bom()
   %bw!
 endfunc
 
+func Test_read_write_bin()
+  " write file missing EOL
+  call writefile(['noeol'], "XNoEolSetEol", 'bS')
+  call assert_equal(0z6E6F656F6C, readfile('XNoEolSetEol', 'B'))
+
+  " when file is read 'eol' is off
+  set ff=unix nofixeol
+  e XNoEolSetEol
+  call assert_equal(0, &eol)
+
+  " writing with 'eol' set adds the newline
+  setlocal eol
+  w
+  call assert_equal(0z6E6F656F6C0A, readfile('XNoEolSetEol', 'B'))
+
+  call delete('XNoEolSetEol')
+endfunc
+
 " vim: shiftwidth=2 sts=2 expandtab
index af89c9e305d6fc0d28374ee2c2b944c9d69240e5..0fadf6b930b5eb7822ab4bb2b06506633c968179 100644 (file)
@@ -750,6 +750,8 @@ static char *(features[]) =
 
 static int included_patches[] =
 {   /* Add new patch number below this line */
+/**/
+    2199,
 /**/
     2198,
 /**/