summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorh2so5 <[email protected]>2014-12-17 14:01:39 +0900
committerh2so5 <[email protected]>2014-12-17 14:01:39 +0900
commit05b00a14c5081ee4bf362b12839dcbb94df1169a (patch)
treec5bd63ebe420a615bc003058a917bf70f553f866
parent5b203ead1e5f642af7bbb2c1b4d28cf4c5737633 (diff)
downloadmruby-05b00a14c5081ee4bf362b12839dcbb94df1169a.tar.gz
mruby-05b00a14c5081ee4bf362b12839dcbb94df1169a.zip
String#[] should reject nil index
-rw-r--r--src/string.c1
-rw-r--r--test/t/string.rb4
2 files changed, 5 insertions, 0 deletions
diff --git a/src/string.c b/src/string.c
index 1c54ffa72..2b1a27fee 100644
--- a/src/string.c
+++ b/src/string.c
@@ -781,6 +781,7 @@ num_index:
}
}
default:
+ if (mrb_nil_p(indx)) mrb_raise(mrb, E_TYPE_ERROR, "can't convert nil into Integer");
idx = mrb_fixnum(indx);
goto num_index;
}
diff --git a/test/t/string.rb b/test/t/string.rb
index a56862fe2..63e4af000 100644
--- a/test/t/string.rb
+++ b/test/t/string.rb
@@ -72,6 +72,10 @@ assert('String#[]', '15.2.10.5.6') do
assert_equal 'bc', e1
assert_equal 'bc', a3
assert_nil b3
+
+ assert_raise(TypeError) do
+ a[nil]
+ end
end
assert('String#[] with Range') do