patch 9.1.2015: blob2string() stopped after an empty line

Commit: 
https://github.com/vim/vim/commit/60c87056b4d0e8fc57f164eb3a9d96796178eb6a
Author: Foxe Chen <[email protected]>
Date:   Tue Dec 23 20:37:19 2025 +0000

    patch 9.1.2015: blob2string() stopped after an empty line
    
    Problem:  blob2string() stopped after an empty line
    Solution: Specifically check for empty content (Foxe Chen)
    
    closes: #19001
    
    Signed-off-by: Foxe Chen <[email protected]>
    Signed-off-by: Christian Brabandt <[email protected]>

diff --git a/src/strings.c b/src/strings.c
index 228cff242..b54878302 100644
--- a/src/strings.c
+++ b/src/strings.c
@@ -1234,6 +1234,8 @@ blob_from_string(char_u *str, blob_T *blob)
  * Return a string created from the bytes in blob starting at "start_idx".
  * A NL character in the blob indicates end of string.
  * A NUL character in the blob is translated to a NL.
+ * If a newline is followed by another newline (empty line), then an empty
+ * allocated string is returned and "start_idx" is moved forward by one byte.
  * On return, "start_idx" points to next byte to process in blob.
  */
     static char_u *
@@ -1265,6 +1267,8 @@ string_from_blob(blob_T *blob, long *start_idx)
 
     if (str_ga.ga_data != NULL)
        ret_str = vim_strnsave(str_ga.ga_data, str_ga.ga_len);
+    else
+       ret_str = vim_strsave((char_u *)"");
     *start_idx = idx;
 
     ga_clear(&str_ga);
diff --git a/src/testdir/test_blob.vim b/src/testdir/test_blob.vim
index a70cdcf61..1ce227d5c 100644
--- a/src/testdir/test_blob.vim
+++ b/src/testdir/test_blob.vim
@@ -885,4 +885,17 @@ func Test_blob_byte_set_invalid_value()
   call v9.CheckSourceLegacyAndVim9Failure(lines, 'E1239: Invalid value for 
blob:')
 endfunc
 
+" Test when converting a blob to a string, and there is an empty line (newline
+" followed directly by another newline).
+func Test_blob2str_empty_line()
+  let stuff =<< trim END
+  Hello
+
+  World!
+  END
+
+  let b = str2blob(stuff)
+  call assert_equal(['Hello', '', 'World!'], blob2str(b))
+endfunc
+
 " vim: shiftwidth=2 sts=2 expandtab
diff --git a/src/version.c b/src/version.c
index 77c2fd181..75714149c 100644
--- a/src/version.c
+++ b/src/version.c
@@ -734,6 +734,8 @@ static char *(features[]) =
 
 static int included_patches[] =
 {   /* Add new patch number below this line */
+/**/
+    2015,
 /**/
     2014,
 /**/

-- 
-- 
You received this message from the "vim_dev" maillist.
Do not top-post! Type your reply below the text you are replying to.
For more information, visit http://www.vim.org/maillist.php

--- 
You received this message because you are subscribed to the Google Groups 
"vim_dev" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To view this discussion visit 
https://groups.google.com/d/msgid/vim_dev/E1vY9Fh-00CH9v-IR%40256bit.org.

Raspunde prin e-mail lui