1
0
Fork 0
mirror of https://github.com/ruby/ruby.git synced 2022-11-09 12:17:21 -05:00

* 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.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@35120 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
nobu 2012-03-23 04:19:24 +00:00
parent a13486997a
commit 163ab0a4da
6 changed files with 32 additions and 10 deletions

View file

@ -1,3 +1,10 @@
Fri Mar 23 13:19:20 2012 Nobuyoshi Nakada <nobu@ruby-lang.org>
* 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@ruby-lang.org>
* transcode.c (str_encode_bang, encoded_dup): if nothing was

View file

@ -775,6 +775,7 @@ rb_str_to_inum(VALUE str, int base, int badcheck)
VALUE ret;
StringValue(str);
rb_must_asciicompat(str);
if (badcheck) {
s = StringValueCStr(str);
}

View file

@ -707,6 +707,7 @@ VALUE rb_str_buf_cat2(VALUE, const char*);
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);

View file

@ -1409,6 +1409,15 @@ rb_str_associated(VALUE str)
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 @@ rb_str_scan(VALUE str, VALUE pat)
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 @@ rb_str_hex(VALUE str)
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);
}

View file

@ -90,6 +90,13 @@ class TestInteger < Test::Unit::TestCase
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

View file

@ -1465,6 +1465,13 @@ class TestString < Test::Unit::TestCase
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