]> git.ipfire.org Git - thirdparty/vim.git/commitdiff
patch 9.1.2120: blob2str() does not restore trailing newline v9.1.2120
authorthinca <thinca@gmail.com>
Sat, 31 Jan 2026 09:52:00 +0000 (09:52 +0000)
committerChristian Brabandt <cb@256bit.org>
Sat, 31 Jan 2026 09:52:00 +0000 (09:52 +0000)
Problem:  blob2str() does not restore trailing newline
Solution: Append empty string (thinca).

closes: #19288

Signed-off-by: thinca <thinca@gmail.com>
Signed-off-by: Christian Brabandt <cb@256bit.org>
src/strings.c
src/testdir/test_functions.vim
src/version.c

index 782249fb7502afcfb90a7ac19e679e01c2fa17a1..4d878cb7dbed77fa15d2ea73b6d5da8ae6ca382f 100644 (file)
@@ -1359,6 +1359,10 @@ f_blob2str(typval_T *argvars, typval_T *rettv)
            break;
     }
 
+    // If the blob ends with a newline, we need to add another empty string.
+    if (blen > 0 && blob_get(blob, blen - 1) == NL)
+       list_append_string(rettv->vval.v_list, (char_u *)"", 0);
+
 done:
     vim_free(from_encoding);
 }
index 9dba0b3f315490af84b7d5f4a334aedd363dd639..2fa09eddc0f15ba27856e5b748b6759867bfffb4 100644 (file)
@@ -4512,6 +4512,7 @@ func Test_blob2str()
     call assert_equal(["ab"], blob2str(0z6162))
     call assert_equal(["a\nb"], blob2str(0z610062))
     call assert_equal(["ab", "cd"], blob2str(0z61620A6364))
+    call assert_equal(["ab", "cd", ""], blob2str(0z61620A63640A))
 
     call assert_equal(["«»"], blob2str(0zC2ABC2BB))
     call assert_equal(["ŝş"], blob2str(0zC59DC59F))
index b52290a8593d3aef07f9fc5facb46e9816edcfdb..94b463ebe0e37dbb97bb17faa9d7d1661191333a 100644 (file)
@@ -734,6 +734,8 @@ static char *(features[]) =
 
 static int included_patches[] =
 {   /* Add new patch number below this line */
+/**/
+    2120,
 /**/
     2119,
 /**/