mirror of
https://github.com/ruby/ruby.git
synced 2022-11-09 12:17:21 -05:00
* ext/iconv/iconv.c (strip_glibc_option, map_charset): check if
encoding is a string. based on the patch by Hiroshi Moriyama at [ruby-dev:36811]. * test/iconv/test_basic.rb (test_invalid_arguments): added tests. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@19866 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
parent
4442095d4c
commit
5225f2c143
3 changed files with 18 additions and 2 deletions
|
@ -1,3 +1,11 @@
|
||||||
|
Tue Oct 21 11:34:04 2008 Nobuyoshi Nakada <nobu@ruby-lang.org>
|
||||||
|
|
||||||
|
* ext/iconv/iconv.c (strip_glibc_option, map_charset): check if
|
||||||
|
encoding is a string. based on the patch by Hiroshi Moriyama at
|
||||||
|
[ruby-dev:36811].
|
||||||
|
|
||||||
|
* test/iconv/test_basic.rb (test_invalid_arguments): added tests.
|
||||||
|
|
||||||
Tue Oct 21 10:40:37 2008 Nobuyoshi Nakada <nobu@ruby-lang.org>
|
Tue Oct 21 10:40:37 2008 Nobuyoshi Nakada <nobu@ruby-lang.org>
|
||||||
|
|
||||||
* io.c (rb_file_open_internal): should initialize fmode before using.
|
* io.c (rb_file_open_internal): should initialize fmode before using.
|
||||||
|
|
|
@ -144,9 +144,10 @@ charset_map_get(void)
|
||||||
static VALUE
|
static VALUE
|
||||||
strip_glibc_option(VALUE *code)
|
strip_glibc_option(VALUE *code)
|
||||||
{
|
{
|
||||||
VALUE val = *code;
|
VALUE val = StringValue(*code);
|
||||||
const char *ptr = RSTRING_PTR(val), *pend = RSTRING_END(val);
|
const char *ptr = RSTRING_PTR(val), *pend = RSTRING_END(val);
|
||||||
const char *slash = memchr(ptr, '/', pend - ptr);
|
const char *slash = memchr(ptr, '/', pend - ptr);
|
||||||
|
|
||||||
if (slash && slash < pend - 1 && slash[1] == '/') {
|
if (slash && slash < pend - 1 && slash[1] == '/') {
|
||||||
VALUE opt = rb_str_subseq(val, slash - ptr, pend - slash);
|
VALUE opt = rb_str_subseq(val, slash - ptr, pend - slash);
|
||||||
val = rb_str_subseq(val, 0, slash - ptr);
|
val = rb_str_subseq(val, 0, slash - ptr);
|
||||||
|
@ -159,7 +160,7 @@ strip_glibc_option(VALUE *code)
|
||||||
static char *
|
static char *
|
||||||
map_charset(VALUE *code)
|
map_charset(VALUE *code)
|
||||||
{
|
{
|
||||||
VALUE val = *code;
|
VALUE val = StringValue(*code);
|
||||||
|
|
||||||
if (RHASH_SIZE(charset_map)) {
|
if (RHASH_SIZE(charset_map)) {
|
||||||
VALUE key = rb_funcall2(val, rb_intern("downcase"), 0, 0);
|
VALUE key = rb_funcall2(val, rb_intern("downcase"), 0, 0);
|
||||||
|
|
|
@ -43,6 +43,13 @@ class TestIconv::Basic < TestIconv
|
||||||
assert_equal("#{SJIS_STR}\n"*2, output)
|
assert_equal("#{SJIS_STR}\n"*2, output)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def test_invalid_arguments
|
||||||
|
assert_raise(TypeError) { Iconv.new(nil, 'Shift_JIS') }
|
||||||
|
assert_raise(TypeError) { Iconv.new('Shift_JIS', nil) }
|
||||||
|
assert_raise(TypeError) { Iconv.open(nil, 'Shift_JIS') }
|
||||||
|
assert_raise(TypeError) { Iconv.open('Shift_JIS', nil) }
|
||||||
|
end
|
||||||
|
|
||||||
def test_unknown_encoding
|
def test_unknown_encoding
|
||||||
assert_raise(Iconv::InvalidEncoding) { Iconv.iconv("utf-8", "X-UKNOWN", "heh") }
|
assert_raise(Iconv::InvalidEncoding) { Iconv.iconv("utf-8", "X-UKNOWN", "heh") }
|
||||||
end
|
end
|
||||||
|
|
Loading…
Reference in a new issue