From 5a41626dea072a4493984f05ba3aa032919da70d Mon Sep 17 00:00:00 2001 From: matz Date: Mon, 17 Dec 2007 05:01:47 +0000 Subject: [PATCH] * string.c (tr_find): wrong condition fixed. * sprintf.c (rb_str_format): check encoding based on result, not the format string. * string.c (rb_str_upto): add encoding check. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@14256 b2dd03c8-39d4-4d8f-98ff-823fe69b080e --- ChangeLog | 9 +++++++++ sprintf.c | 4 +++- string.c | 10 ++++++---- 3 files changed, 18 insertions(+), 5 deletions(-) diff --git a/ChangeLog b/ChangeLog index 58b9381c36..149f8ea160 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,12 @@ +Mon Dec 17 13:56:53 2007 Yukihiro Matsumoto + + * string.c (tr_find): wrong condition fixed. + + * sprintf.c (rb_str_format): check encoding based on result, not + the format string. + + * string.c (rb_str_upto): add encoding check. + Mon Dec 17 12:21:25 2007 Nobuyoshi Nakada * Makefile.in (RUNRUBY): added RUNRUBYOPT. diff --git a/sprintf.c b/sprintf.c index 0835dab3d1..f005ad6af4 100644 --- a/sprintf.c +++ b/sprintf.c @@ -296,6 +296,7 @@ rb_str_format(int argc, const VALUE *argv, VALUE fmt) blen = 0; bsiz = 120; result = rb_str_buf_new(bsiz); + rb_enc_copy(result, fmt); buf = RSTRING_PTR(result); for (; p < end; p++) { @@ -459,7 +460,7 @@ rb_str_format(int argc, const VALUE *argv, VALUE fmt) str = rb_obj_as_string(arg); if (OBJ_TAINTED(str)) tainted = 1; len = RSTRING_LEN(str); - enc = rb_enc_check(fmt, str); + enc = rb_enc_check(result, str); if (flags&(FPREC|FWIDTH)) { slen = rb_enc_strlen(RSTRING_PTR(str),RSTRING_END(str),enc); if (slen < 0) { @@ -497,6 +498,7 @@ rb_str_format(int argc, const VALUE *argv, VALUE fmt) } } PUSH(RSTRING_PTR(str), len); + rb_enc_associate(result, enc); } break; diff --git a/string.c b/string.c index 0857596cd0..62ade2ae54 100644 --- a/string.c +++ b/string.c @@ -1945,6 +1945,7 @@ rb_str_upto(int argc, VALUE *argv, VALUE beg) int n, excl; rb_scan_args(argc, argv, "11", &end, &exclusive); + rb_enc_check(beg, end); excl = RTEST(exclusive); succ = rb_intern("succ"); StringValue(end); @@ -3741,11 +3742,12 @@ tr_find(int c, char table[256], VALUE del, VALUE nodel) else { VALUE v = INT2NUM(c); - if ((!del || !NIL_P(rb_hash_lookup(del, v))) && - (!nodel || NIL_P(rb_hash_lookup(nodel, v)))) { - return Qtrue; + if (!del || NIL_P(rb_hash_lookup(del, v))) { + return Qfalse; } - return Qfalse; + if (nodel && NIL_P(rb_hash_lookup(nodel, v))) + return Qfalse; + return Qtrue; } }