Skip to content

Commit 60c8705

Browse files
64-bitmanchrisbra
authored andcommitted
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.foxe@gmail.com> Signed-off-by: Christian Brabandt <cb@256bit.org>
1 parent 11c3c62 commit 60c8705

3 files changed

Lines changed: 19 additions & 0 deletions

File tree

src/strings.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1234,6 +1234,8 @@ blob_from_string(char_u *str, blob_T *blob)
12341234
* Return a string created from the bytes in blob starting at "start_idx".
12351235
* A NL character in the blob indicates end of string.
12361236
* A NUL character in the blob is translated to a NL.
1237+
* If a newline is followed by another newline (empty line), then an empty
1238+
* allocated string is returned and "start_idx" is moved forward by one byte.
12371239
* On return, "start_idx" points to next byte to process in blob.
12381240
*/
12391241
static char_u *
@@ -1265,6 +1267,8 @@ string_from_blob(blob_T *blob, long *start_idx)
12651267

12661268
if (str_ga.ga_data != NULL)
12671269
ret_str = vim_strnsave(str_ga.ga_data, str_ga.ga_len);
1270+
else
1271+
ret_str = vim_strsave((char_u *)"");
12681272
*start_idx = idx;
12691273

12701274
ga_clear(&str_ga);

src/testdir/test_blob.vim

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -885,4 +885,17 @@ func Test_blob_byte_set_invalid_value()
885885
call v9.CheckSourceLegacyAndVim9Failure(lines, 'E1239: Invalid value for blob:')
886886
endfunc
887887

888+
" Test when converting a blob to a string, and there is an empty line (newline
889+
" followed directly by another newline).
890+
func Test_blob2str_empty_line()
891+
let stuff =<< trim END
892+
Hello
893+
894+
World!
895+
END
896+
897+
let b = str2blob(stuff)
898+
call assert_equal(['Hello', '', 'World!'], blob2str(b))
899+
endfunc
900+
888901
" vim: shiftwidth=2 sts=2 expandtab

src/version.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -734,6 +734,8 @@ static char *(features[]) =
734734

735735
static int included_patches[] =
736736
{ /* Add new patch number below this line */
737+
/**/
738+
2015,
737739
/**/
738740
2014,
739741
/**/

0 commit comments

Comments
 (0)