ruby-changes:45005
From: rhe <ko1@a...>
Date: Wed, 14 Dec 2016 21:32:49 +0900 (JST)
Subject: [ruby-changes:45005] rhe:r57078 (trunk): encoding.c: handle needmore error from rb_enc_precise_mbclen()
rhe 2016-12-14 21:32:42 +0900 (Wed, 14 Dec 2016) New Revision: 57078 https://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=revision&revision=57078 Log: encoding.c: handle needmore error from rb_enc_precise_mbclen() rb_enc_ascget() erroneously reports success even if the given byte sequence is incomplete, for non-ASCII compatible encoding strings. rb_enc_precise_mbclen() may return a negative value on error, and thus rb_enc_ascget() must not store the return value in 'unsigned int'; otherwise the subsequent MBCLEN_CHARFOUND_P() check won't catch the error. [ruby-core:78646] [Bug #13034] Modified files: trunk/encoding.c trunk/test/ruby/test_regexp.rb Index: test/ruby/test_regexp.rb =================================================================== --- test/ruby/test_regexp.rb (revision 57077) +++ test/ruby/test_regexp.rb (revision 57078) @@ -567,6 +567,10 @@ class TestRegexp < Test::Unit::TestCase https://github.com/ruby/ruby/blob/trunk/test/ruby/test_regexp.rb#L567 assert_equal("\\v", Regexp.quote("\v")) assert_equal("\u3042\\t", Regexp.quote("\u3042\t")) assert_equal("\\t\xff", Regexp.quote("\t" + [0xff].pack("C"))) + + bug13034 = '[ruby-core:78646] [Bug #13034]' + str = "\x00".force_encoding("UTF-16BE") + assert_equal(str, Regexp.quote(str), bug13034) end def test_try_convert Index: encoding.c =================================================================== --- encoding.c (revision 57077) +++ encoding.c (revision 57078) @@ -1031,7 +1031,8 @@ rb_enc_precise_mbclen(const char *p, con https://github.com/ruby/ruby/blob/trunk/encoding.c#L1031 int rb_enc_ascget(const char *p, const char *e, int *len, rb_encoding *enc) { - unsigned int c, l; + unsigned int c; + int l; if (e <= p) return -1; if (rb_enc_asciicompat(enc)) { -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/