]> git.ipfire.org Git - thirdparty/vim.git/commitdiff
patch 9.1.1558: str2blob() treats NULL string and empty string differently v9.1.1558
authorzeertzjq <zeertzjq@outlook.com>
Thu, 17 Jul 2025 18:12:17 +0000 (20:12 +0200)
committerChristian Brabandt <cb@256bit.org>
Thu, 17 Jul 2025 18:12:17 +0000 (20:12 +0200)
Problem:  str2blob() treats NULL string and empty string differently
Solution: Treats a NULL string the same as an empty string
          (zeertzjq).

closes: #17778

Signed-off-by: zeertzjq <zeertzjq@outlook.com>
Signed-off-by: Yegappan Lakshmanan <yegappan@yahoo.com>
Signed-off-by: Christian Brabandt <cb@256bit.org>
src/strings.c
src/testdir/test_functions.vim
src/version.c

index c356c36665583f09f4cf5d6561cbc1e4bbcd0e70..87868b90c4cc61c0617008f0a441d99c999d3017 100644 (file)
@@ -1407,7 +1407,7 @@ f_str2blob(typval_T *argvars, typval_T *rettv)
        char_u  *str = li->li_tv.vval.v_string;
 
        if (str == NULL)
-           continue;
+           str = (char_u *)"";
 
        if (to_encoding != NULL)
        {
index 4fac4726fa91a1f5d1fa04b3912fc5a297dada53..fccd5af4911e6d01d23695dd7151035606712941 100644 (file)
@@ -4411,13 +4411,17 @@ func Test_str2blob()
     call assert_equal(0z, str2blob([""]))
     call assert_equal(0z, str2blob([]))
     call assert_equal(0z, str2blob(test_null_list()))
-    call assert_equal(0z, str2blob([test_null_string(), test_null_string()]))
+    call assert_equal(0z, str2blob([test_null_string()]))
+    call assert_equal(0z0A, str2blob([test_null_string(), test_null_string()]))
     call assert_fails("call str2blob('')", 'E1211: List required for argument 1')
     call assert_equal(0z61, str2blob(["a"]))
     call assert_equal(0z6162, str2blob(["ab"]))
     call assert_equal(0z610062, str2blob(["a\nb"]))
     call assert_equal(0z61620A6364, str2blob(["ab", "cd"]))
     call assert_equal(0z0A, str2blob(["", ""]))
+    call assert_equal(0z610A62, str2blob(["a", "b"]))
+    call assert_equal(0z610A0A62, str2blob(["a", "", "b"]))
+    call assert_equal(0z610A0A62, str2blob(["a", test_null_string(), "b"]))
 
     call assert_equal(0zC2ABC2BB, str2blob(["«»"]))
     call assert_equal(0zC59DC59F, str2blob(["ŝş"]))
index d2710bc1a426f96bfd5316eea043ec0a3c185666..638dfc6bbe6abfe4b6d9a585b0df995a179bc4d1 100644 (file)
@@ -719,6 +719,8 @@ static char *(features[]) =
 
 static int included_patches[] =
 {   /* Add new patch number below this line */
+/**/
+    1558,
 /**/
     1557,
 /**/