diff options
-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 e0da2a5b6..844b79220 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); |