From: Foxe Chen Date: Tue, 23 Dec 2025 20:37:19 +0000 (+0000) Subject: patch 9.1.2015: blob2string() stopped after an empty line X-Git-Tag: v9.1.2015^0 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=60c87056b4d0e8fc57f164eb3a9d96796178eb6a;p=thirdparty%2Fvim.git 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 Signed-off-by: Christian Brabandt --- diff --git a/src/strings.c b/src/strings.c index 228cff242c..b548783022 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 a70cdcf61d..1ce227d5cf 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 77c2fd181b..75714149c3 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, /**/