mirror of
https://github.com/ruby/ruby.git
synced 2022-11-09 12:17:21 -05:00
object.c: use converted string
* object.c (rb_convert_to_integer): should not drop the converted string. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@56495 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
parent
54354c0613
commit
9396660a4a
3 changed files with 10 additions and 2 deletions
|
@ -1,3 +1,8 @@
|
||||||
|
Thu Oct 27 09:12:32 2016 Nobuyoshi Nakada <nobu@ruby-lang.org>
|
||||||
|
|
||||||
|
* object.c (rb_convert_to_integer): should not drop the converted
|
||||||
|
string.
|
||||||
|
|
||||||
Wed Oct 26 17:09:59 2016 Nobuyoshi Nakada <nobu@ruby-lang.org>
|
Wed Oct 26 17:09:59 2016 Nobuyoshi Nakada <nobu@ruby-lang.org>
|
||||||
|
|
||||||
* include/ruby/ruby.h (rb_intern): use prefixed version macro
|
* include/ruby/ruby.h (rb_intern): use prefixed version macro
|
||||||
|
|
3
object.c
3
object.c
|
@ -2699,7 +2699,6 @@ rb_convert_to_integer(VALUE val, int base)
|
||||||
return val;
|
return val;
|
||||||
|
|
||||||
case T_STRING:
|
case T_STRING:
|
||||||
string_conv:
|
|
||||||
return rb_str_to_inum(val, base, TRUE);
|
return rb_str_to_inum(val, base, TRUE);
|
||||||
|
|
||||||
case T_NIL:
|
case T_NIL:
|
||||||
|
@ -2712,7 +2711,7 @@ rb_convert_to_integer(VALUE val, int base)
|
||||||
}
|
}
|
||||||
if (base != 0) {
|
if (base != 0) {
|
||||||
tmp = rb_check_string_type(val);
|
tmp = rb_check_string_type(val);
|
||||||
if (!NIL_P(tmp)) goto string_conv;
|
if (!NIL_P(tmp)) return rb_str_to_inum(tmp, base, TRUE);
|
||||||
arg_error:
|
arg_error:
|
||||||
rb_raise(rb_eArgError, "base specified for non string value");
|
rb_raise(rb_eArgError, "base specified for non string value");
|
||||||
}
|
}
|
||||||
|
|
|
@ -100,6 +100,10 @@ class TestInteger < Test::Unit::TestCase
|
||||||
assert_raise(Encoding::CompatibilityError, bug6192) {Integer("0".encode("iso-2022-jp"))}
|
assert_raise(Encoding::CompatibilityError, bug6192) {Integer("0".encode("iso-2022-jp"))}
|
||||||
|
|
||||||
assert_raise_with_message(ArgumentError, /\u{1f4a1}/) {Integer("\u{1f4a1}")}
|
assert_raise_with_message(ArgumentError, /\u{1f4a1}/) {Integer("\u{1f4a1}")}
|
||||||
|
|
||||||
|
obj = Struct.new(:s).new(%w[42 not-an-integer])
|
||||||
|
def obj.to_str; s.shift; end
|
||||||
|
assert_equal(42, Integer(obj, 10))
|
||||||
end
|
end
|
||||||
|
|
||||||
def test_int_p
|
def test_int_p
|
||||||
|
|
Loading…
Add table
Reference in a new issue