diff --git a/ChangeLog b/ChangeLog index 5f10c1e53e..81cf7e30d8 100644 --- a/ChangeLog +++ b/ChangeLog @@ -3,6 +3,14 @@ Fri Oct 17 18:07:17 2008 Nobuyoshi Nakada * test/rubygems/gemutilities.rb (RubyGemTestCase#build_rake_in): get rid of interference with other tests. +Fri Oct 17 18:06:39 2008 Yukihiro Matsumoto + + * transcode.c (str_transcode0): String#encode without argument now + behave as if :undef => :replace, :invalid => :replace specified. + + * transcode.c (rb_econv_prepare_opts): should preserve options in + any case. + Fri Oct 17 11:48:18 2008 Shugo Maeda * ext/socket/socket.c (init_sock): sockets should be binmode. diff --git a/transcode.c b/transcode.c index 5031d49989..6d02875051 100644 --- a/transcode.c +++ b/transcode.c @@ -2307,28 +2307,27 @@ rb_econv_prepare_opts(VALUE opthash, VALUE *opts) { int ecflags; VALUE newhash = Qnil; + VALUE v; + if (NIL_P(opthash)) { *opts = Qnil; return 0; } ecflags = econv_opts(opthash); - - if ((ecflags & ECONV_INVALID_MASK) == ECONV_INVALID_REPLACE || - (ecflags & ECONV_UNDEF_MASK) == ECONV_UNDEF_REPLACE) { - VALUE v = rb_hash_aref(opthash, sym_replace); - if (!NIL_P(v)) { - StringValue(v); - if (rb_enc_str_coderange(v) == ENC_CODERANGE_BROKEN) { - VALUE dumped = rb_str_dump(v); - rb_raise(rb_eArgError, "replacement string is broken: %s as %s", - StringValueCStr(dumped), - rb_enc_name(rb_enc_get(v))); - } - v = rb_str_new_frozen(v); - newhash = rb_hash_new(); - rb_hash_aset(newhash, sym_replace, v); - } + v = rb_hash_aref(opthash, sym_replace); + if (!NIL_P(v)) { + StringValue(v); + if (rb_enc_str_coderange(v) == ENC_CODERANGE_BROKEN) { + VALUE dumped = rb_str_dump(v); + rb_raise(rb_eArgError, "replacement string is broken: %s as %s", + StringValueCStr(dumped), + rb_enc_name(rb_enc_get(v))); + } + v = rb_str_new_frozen(v); + newhash = rb_hash_new(); + rb_hash_aset(newhash, sym_replace, v); } + if (!NIL_P(newhash)) rb_hash_freeze(newhash); *opts = newhash; @@ -2444,6 +2443,7 @@ str_transcode0(int argc, VALUE *argv, VALUE *self, int ecflags, VALUE ecopts) if (NIL_P(arg1)) { return -1; } + ecflags |= ECONV_INVALID_REPLACE | ECONV_UNDEF_REPLACE; } else { arg1 = argv[0];