ruby-changes:23070
From: nobu <ko1@a...>
Date: Fri, 23 Mar 2012 13:19:41 +0900 (JST)
Subject: [ruby-changes:23070] nobu:r35120 (trunk): * bignum.c (rb_str_to_inum): must be ASCII compatible encoding as
nobu 2012-03-23 13:19:24 +0900 (Fri, 23 Mar 2012) New Revision: 35120 http://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=rev&revision=35120 Log: * bignum.c (rb_str_to_inum): must be ASCII compatible encoding as well as String#hex and String#oct. [ruby-core:43566][Bug #6192] * string.c (rb_must_asciicompat): check if ASCII compatible. Modified files: trunk/ChangeLog trunk/bignum.c trunk/include/ruby/intern.h trunk/string.c trunk/test/ruby/test_integer.rb trunk/test/ruby/test_string.rb Index: include/ruby/intern.h =================================================================== --- include/ruby/intern.h (revision 35119) +++ include/ruby/intern.h (revision 35120) @@ -707,6 +707,7 @@ VALUE rb_str_buf_cat_ascii(VALUE, const char*); VALUE rb_obj_as_string(VALUE); VALUE rb_check_string_type(VALUE); +void rb_must_asciicompat(VALUE); VALUE rb_str_dup(VALUE); VALUE rb_str_resurrect(VALUE str); VALUE rb_str_locktmp(VALUE); Index: ChangeLog =================================================================== --- ChangeLog (revision 35119) +++ ChangeLog (revision 35120) @@ -1,3 +1,10 @@ +Fri Mar 23 13:19:20 2012 Nobuyoshi Nakada <nobu@r...> + + * bignum.c (rb_str_to_inum): must be ASCII compatible encoding as + well as String#hex and String#oct. [ruby-core:43566][Bug #6192] + + * string.c (rb_must_asciicompat): check if ASCII compatible. + Thu Mar 22 23:14:36 2012 Nobuyoshi Nakada <nobu@r...> * transcode.c (str_encode_bang, encoded_dup): if nothing was Index: string.c =================================================================== --- string.c (revision 35119) +++ string.c (revision 35120) @@ -1409,6 +1409,15 @@ return Qfalse; } +void +rb_must_asciicompat(VALUE str) +{ + rb_encoding *enc = rb_enc_get(str); + if (!rb_enc_asciicompat(enc)) { + rb_raise(rb_eEncCompatError, "ASCII incompatible encoding: %s", rb_enc_name(enc)); + } +} + VALUE rb_string_value(volatile VALUE *ptr) { @@ -6722,11 +6731,6 @@ static VALUE rb_str_hex(VALUE str) { - rb_encoding *enc = rb_enc_get(str); - - if (!rb_enc_asciicompat(enc)) { - rb_raise(rb_eEncCompatError, "ASCII incompatible encoding: %s", rb_enc_name(enc)); - } return rb_str_to_inum(str, 16, FALSE); } @@ -6748,11 +6752,6 @@ static VALUE rb_str_oct(VALUE str) { - rb_encoding *enc = rb_enc_get(str); - - if (!rb_enc_asciicompat(enc)) { - rb_raise(rb_eEncCompatError, "ASCII incompatible encoding: %s", rb_enc_name(enc)); - } return rb_str_to_inum(str, -8, FALSE); } Index: bignum.c =================================================================== --- bignum.c (revision 35119) +++ bignum.c (revision 35120) @@ -775,6 +775,7 @@ VALUE ret; StringValue(str); + rb_must_asciicompat(str); if (badcheck) { s = StringValueCStr(str); } Index: test/ruby/test_integer.rb =================================================================== --- test/ruby/test_integer.rb (revision 35119) +++ test/ruby/test_integer.rb (revision 35120) @@ -90,6 +90,13 @@ assert_equal(2 ** 50, Integer(2.0 ** 50)) assert_raise(TypeError) { Integer(nil) } + + bug6192 = '[ruby-core:43566]' + assert_raise(Encoding::CompatibilityError, bug6192) {Integer("0".encode("utf-16be"))} + assert_raise(Encoding::CompatibilityError, bug6192) {Integer("0".encode("utf-16le"))} + assert_raise(Encoding::CompatibilityError, bug6192) {Integer("0".encode("utf-32be"))} + assert_raise(Encoding::CompatibilityError, bug6192) {Integer("0".encode("utf-32le"))} + assert_raise(Encoding::CompatibilityError, bug6192) {Integer("0".encode("iso-2022-jp"))} end def test_int_p Index: test/ruby/test_string.rb =================================================================== --- test/ruby/test_string.rb (revision 35119) +++ test/ruby/test_string.rb (revision 35120) @@ -1465,6 +1465,13 @@ assert_equal(0x4000000000000000, "4611686018427387904".to_i(10)) assert_equal(1, "1__2".to_i(10)) assert_equal(1, "1_z".to_i(10)) + + bug6192 = '[ruby-core:43566]' + assert_raise(Encoding::CompatibilityError, bug6192) {"0".encode("utf-16be").to_i} + assert_raise(Encoding::CompatibilityError, bug6192) {"0".encode("utf-16le").to_i} + assert_raise(Encoding::CompatibilityError, bug6192) {"0".encode("utf-32be").to_i} + assert_raise(Encoding::CompatibilityError, bug6192) {"0".encode("utf-32le").to_i} + assert_raise(Encoding::CompatibilityError, bug6192) {"0".encode("iso-2022-jp").to_i} end def test_to_s -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/