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

* transcode.c: added check for frozen string for encode! (see Bug #1836)

* test/ruby/test_transcode.rb: added tests for the above


git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@24322 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
duerst 2009-07-30 09:40:06 +00:00
parent b8b083dbd5
commit 5e85648b77
3 changed files with 12 additions and 0 deletions

View file

@ -1,3 +1,9 @@
Thu Jul 30 18:39:39 2009 Martin Duerst <duerst@it.aoyama.ac.jp>
* transcode.c: added check for frozen string for encode! (see Bug #1836)
* test/ruby/test_transcode.rb: added tests for the above
Thu Jul 30 16:45:39 2009 Nobuyoshi Nakada <nobu@ruby-lang.org>
* insns.def (defineclass): preserve encoding of class/module

View file

@ -11,6 +11,8 @@ class TestTranscode < Test::Unit::TestCase
assert_raise(Encoding::UndefinedConversionError) { "\x80".encode('utf-8','ASCII-8BIT') }
assert_raise(Encoding::InvalidByteSequenceError) { "\x80".encode('utf-8','US-ASCII') }
assert_raise(Encoding::UndefinedConversionError) { "\xA5".encode('utf-8','iso-8859-3') }
assert_raise(RuntimeError) { 'hello'.freeze.encode!('iso-8859-1') }
assert_raise(RuntimeError) { '\u3053\u3093\u306b\u3061\u306f'.freeze.encode!('iso-8859-1') } # こんにちは
end
def test_arguments

View file

@ -2644,6 +2644,10 @@ str_encode_associate(VALUE str, int encidx)
static VALUE
str_encode_bang(int argc, VALUE *argv, VALUE str)
{
if (OBJ_FROZEN(str)) { /* in future, may use str_frozen_check from string.c, but that's currently static */
rb_raise(rb_eRuntimeError, "string frozen");
}
VALUE newstr = str;
int encidx = str_transcode(argc, argv, &newstr);