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

* encoding.c (enc_find): check type of argument and convert to String

if it is StringValue. [ruby-cvs:22866]

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@15631 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
naruse 2008-02-28 11:58:11 +00:00
parent 1f262b3ef4
commit 6f99342c92
4 changed files with 13 additions and 5 deletions

View file

@ -1,3 +1,8 @@
Thu Feb 28 19:45:52 2008 NARUSE, Yui <naruse@ruby-lang.org>
* encoding.c (enc_find): check type of argument and convert to String
if it is StringValue. [ruby-cvs:22866]
Thu Feb 28 18:07:52 2008 Tanaka Akira <akr@fsij.org>
* lib/open-uri.rb (OpenURI::Meta#meta_setup_encoding): setup encoding

View file

@ -57,7 +57,3 @@ assert_normal_exit %q{
assert_normal_exit %q{
"".center(1, "\x80".force_encoding("utf-8"))
}, '[ruby-dev:33807]'
assert_normal_exit %q{
Encoding.find(nil)
}

View file

@ -902,7 +902,7 @@ enc_find(VALUE klass, VALUE enc)
{
int idx;
if (SYMBOL_P(enc)) enc = rb_id2str(SYM2ID(enc));
StringValue(enc);
if (!rb_enc_asciicompat(rb_enc_get(enc))) {
rb_raise(rb_eArgError, "invalid name encoding (non ASCII)");
}

View file

@ -1113,6 +1113,13 @@ class TestM17N < Test::Unit::TestCase
assert_equal(Encoding::US_ASCII, {1=>nil,"foo"=>""}.to_s.encoding)
end
def test_encoding_find
assert_raise(TypeError) {Encoding.find(nil)}
assert_raise(TypeError) {Encoding.find(0)}
assert_raise(TypeError) {Encoding.find([])}
assert_raise(TypeError) {Encoding.find({})}
end
def test_encoding_to_s
assert_equal(Encoding::US_ASCII, Encoding::US_ASCII.to_s.encoding)
assert_equal(Encoding::US_ASCII, Encoding::US_ASCII.inspect.encoding)