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

* 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
This commit is contained in:
nobu 2007-12-04 10:56:44 +00:00
parent 6ccd9e0372
commit 398cdd3825
2 changed files with 12 additions and 4 deletions

View file

@ -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):

View file

@ -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);