diff options
author | nobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2007-12-04 10:56:44 +0000 |
---|---|---|
committer | nobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2007-12-04 10:56:44 +0000 |
commit | 398cdd3825d793f5ed7f7e7e34fc84768cd2af20 (patch) | |
tree | 2ce7b99a75f39efe8c0858c85cc1a8f65eb63ae8 | |
parent | 6ccd9e0372ca172e4f37e80bf12bda2e43952c21 (diff) |
* ext/iconv/iconv.c (iconv_convert): should not set encoding unless
the target encoding is supported. [ruby-dev:32451]
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@14103 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
-rw-r--r-- | ChangeLog | 5 | ||||
-rw-r--r-- | ext/iconv/iconv.c | 11 |
2 files changed, 12 insertions, 4 deletions
@@ -1,3 +1,8 @@ +Tue Dec 4 19:56:42 2007 Nobuyoshi Nakada <nobu@ruby-lang.org> + + * ext/iconv/iconv.c (iconv_convert): should not set encoding unless + the target encoding is supported. [ruby-dev:32451] + Tue Dec 4 17:34:17 2007 NARUSE, Yui <naruse@ruby-lang.org> * ext/nkf/lib/kconv.rb (tojis, tosjis, toeuc, toutf8): diff --git a/ext/iconv/iconv.c b/ext/iconv/iconv.c index e0da2a5b67..844b792208 100644 --- a/ext/iconv/iconv.c +++ b/ext/iconv/iconv.c @@ -336,10 +336,13 @@ iconv_convert(iconv_t cd, VALUE str, int start, int length, struct iconv_env_t* char buffer[BUFSIZ]; char *outptr; size_t outlen; + int toidx = -1; if (cd == (iconv_t)-1) rb_raise(rb_eArgError, "closed iconv"); + if (env) toidx = env->toidx; + if (NIL_P(str)) { /* Reset output pointer or something. */ inptr = ""; @@ -402,7 +405,7 @@ iconv_convert(iconv_t cd, VALUE str, int start, int length, struct iconv_env_t* { if (NIL_P(str)) { ret = rb_str_new(buffer, outlen); - if (env) rb_enc_associate_index(ret, env->toidx); + if (toidx >= 0) rb_enc_associate_index(ret, toidx); } else { if (ret) { @@ -410,7 +413,7 @@ iconv_convert(iconv_t cd, VALUE str, int start, int length, struct iconv_env_t* } else { ret = rb_str_new(instart, tmpstart - instart); - if (env) rb_enc_associate_index(ret, env->toidx); + if (toidx >= 0) rb_enc_associate_index(ret, toidx); OBJ_INFECT(ret, str); } ret = rb_str_buf_cat(ret, buffer, outlen); @@ -432,7 +435,7 @@ iconv_convert(iconv_t cd, VALUE str, int start, int length, struct iconv_env_t* if (!ret) { ret = rb_str_derive(str, instart, inptr - instart); - if (env) rb_enc_associate_index(ret, env->toidx); + if (toidx >= 0) rb_enc_associate_index(ret, toidx); } else if (inptr > instart) { rb_str_cat(ret, instart, inptr - instart); @@ -458,7 +461,7 @@ iconv_convert(iconv_t cd, VALUE str, int start, int length, struct iconv_env_t* if (!ret) { ret = rb_str_derive(str, instart, inptr - instart); - if (env) rb_enc_associate_index(ret, env->toidx); + if (toidx >= 0) rb_enc_associate_index(ret, toidx); } else if (inptr > instart) { rb_str_cat(ret, instart, inptr - instart); |