Commit: patch 9.1.2015: blob2string() stopped after an empty line

3 views
Skip to first unread message

Christian Brabandt

unread,
Dec 23, 2025, 3:45:57 PM (2 days ago) Dec 23
to vim...@googlegroups.com
patch 9.1.2015: blob2string() stopped after an empty line

Commit: https://github.com/vim/vim/commit/60c87056b4d0e8fc57f164eb3a9d96796178eb6a
Author: Foxe Chen <chen...@gmail.com>
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 <chen...@gmail.com>
Signed-off-by: Christian Brabandt <c...@256bit.org>

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,
/**/
Reply all
Reply to author
Forward
0 new messages