mirror of
https://github.com/ruby/ruby.git
synced 2022-11-09 12:17:21 -05:00
encoding.c (enc_set_index): raise instead of rb_bug() for non-encoding capable objects
* Add spec. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@64172 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
parent
a354992688
commit
080d700e1d
2 changed files with 12 additions and 1 deletions
|
@ -819,7 +819,9 @@ rb_enc_get_index(VALUE obj)
|
|||
static void
|
||||
enc_set_index(VALUE obj, int idx)
|
||||
{
|
||||
if (!enc_capable(obj)) rb_bug("enc_set_index: not capable object");
|
||||
if (!enc_capable(obj)) {
|
||||
rb_raise(rb_eArgError, "cannot set encoding on non-encoding capable object");
|
||||
}
|
||||
|
||||
if (idx < ENCODING_INLINE_MAX) {
|
||||
ENCODING_SET_INLINED(obj, idx);
|
||||
|
|
|
@ -30,6 +30,15 @@ describe :rb_enc_set_index, shared: true do
|
|||
result = @s.send(@method, str, 1)
|
||||
result.first.should == result.last
|
||||
end
|
||||
|
||||
ruby_version_is "2.6" do
|
||||
it "raises an ArgumentError for a non-encoding capable object" do
|
||||
obj = Object.new
|
||||
-> {
|
||||
result = @s.send(@method, obj, 1)
|
||||
}.should raise_error(ArgumentError, "cannot set encoding on non-encoding capable object")
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
describe "C-API Encoding function" do
|
||||
|
|
Loading…
Reference in a new issue