]> granicus.if.org Git - vim/commitdiff
patch 8.1.0977: blob not tested with Ruby v8.1.0977
authorBram Moolenaar <Bram@vim.org>
Sat, 23 Feb 2019 13:23:03 +0000 (14:23 +0100)
committerBram Moolenaar <Bram@vim.org>
Sat, 23 Feb 2019 13:23:03 +0000 (14:23 +0100)
Problem:    Blob not tested with Ruby.
Solution:   Add more test coverage.  fixes a crash. (Dominique Pelle,
            closes #4036)

src/if_ruby.c
src/testdir/test_ruby.vim
src/version.c

index d3ed78128114e18b006786a928b555a3fe7ebefe..543ee8ac272564d40e5b0c4ca42d3d2d86cc415e 100644 (file)
@@ -1267,7 +1267,7 @@ static VALUE vim_blob(VALUE self UNUSED, VALUE str)
     int        i;
     for (i = 0; i < RSTRING_LEN(str); i++)
     {
-       sprintf(buf, "%02X", RSTRING_PTR(str)[i]);
+       sprintf(buf, "%02X", (unsigned char)(RSTRING_PTR(str)[i]));
        rb_str_concat(result, rb_str_new2(buf));
     }
     return result;
index 5476e5171f71dd0f924dd172fb6ad76c744838bb..fe2afa6259e014db650256b8bde153792b3718eb 100644 (file)
@@ -306,6 +306,9 @@ func Test_Vim_evaluate()
   call assert_equal('foo',      RubyEval('Vim::evaluate("\"foo\"")'))
   call assert_equal('String',   RubyEval('Vim::evaluate("\"foo\"").class'))
 
+  call assert_equal('["\x01\xAB"]', RubyEval('Vim::evaluate("0z01ab").unpack("M")'))
+  call assert_equal('String',       RubyEval('Vim::evaluate("0z01ab").class'))
+
   call assert_equal('[1, 2]',   RubyEval('Vim::evaluate("[1, 2]")'))
   call assert_equal('Array',    RubyEval('Vim::evaluate("[1, 2]").class'))
 
@@ -324,6 +327,13 @@ func Test_Vim_evaluate()
   call assert_equal('FalseClass',RubyEval('Vim::evaluate("v:false").class'))
 endfunc
 
+func Test_Vim_blob()
+  call assert_equal('0z',         RubyEval('Vim::blob("")'))
+  call assert_equal('0z31326162', RubyEval('Vim::blob("12ab")'))
+  call assert_equal('0z00010203', RubyEval('Vim::blob("\x00\x01\x02\x03")'))
+  call assert_equal('0z8081FEFF', RubyEval('Vim::blob("\x80\x81\xfe\xff")'))
+endfunc
+
 func Test_Vim_evaluate_list()
   call setline(line('$'), ['2 line 2'])
   ruby Vim.command("normal /^2\n")
index b7479254d578c760157247c0e66be799820efd91..8d22ca90e692caf977c311d43ae741519a8c4c4f 100644 (file)
@@ -779,6 +779,8 @@ static char *(features[]) =
 
 static int included_patches[] =
 {   /* Add new patch number below this line */
+/**/
+    977,
 /**/
     976,
 /**/