summaryrefslogtreecommitdiff
path: root/sprintf.c
diff options
context:
space:
mode:
authormatz <matz@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2009-08-11 23:53:21 +0000
committermatz <matz@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2009-08-11 23:53:21 +0000
commit5703c1756cd8a191ecfa62e70fa5d4fb38dedee2 (patch)
treef4835c43fed50c9d1e47e0374dce1ddc8cd9ec4f /sprintf.c
parente666111955d0f48f2bc0283c2867da938b98982c (diff)
* sprintf.c (rb_str_format): should preserve format encoding
before raising CompatibilityError. [ruby-list:46274] git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@24507 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'sprintf.c')
-rw-r--r--sprintf.c10
1 files changed, 5 insertions, 5 deletions
diff --git a/sprintf.c b/sprintf.c
index 6cb024f..4a37ecb 100644
--- a/sprintf.c
+++ b/sprintf.c
@@ -482,6 +482,10 @@ rb_str_format(int argc, const VALUE *argv, VALUE fmt)
for (t = p; t < end && *t != '%'; t++) ;
PUSH(p, t - p);
+ if (coderange != ENC_CODERANGE_BROKEN && scanned < blen) {
+ scanned = rb_str_coderange_scan_restartable(buf+scanned, buf+blen, enc, &coderange);
+ ENC_CODERANGE_SET(result, coderange);
+ }
if (t >= end) {
/* end of fmt string */
goto sprint_exit;
@@ -673,7 +677,7 @@ rb_str_format(int argc, const VALUE *argv, VALUE fmt)
(cr == ENC_CODERANGE_UNKNOWN ?
ENC_CODERANGE_BROKEN : (coderange = cr)));
}
- enc = rb_enc_check(result, str);
+ enc = rb_enc_check((RSTRING_LEN(result) == 0 ? fmt : result), str);
if (flags&(FPREC|FWIDTH)) {
slen = rb_enc_strlen(RSTRING_PTR(str),RSTRING_END(str),enc);
if (slen < 0) {
@@ -1055,10 +1059,6 @@ rb_str_format(int argc, const VALUE *argv, VALUE fmt)
if (RTEST(ruby_debug)) rb_raise(rb_eArgError, "%s", mesg);
if (RTEST(ruby_verbose)) rb_warn("%s", mesg);
}
- if (scanned < blen) {
- rb_str_coderange_scan_restartable(buf+scanned, buf+blen, enc, &coderange);
- ENC_CODERANGE_SET(result, coderange);
- }
rb_str_resize(result, blen);
if (tainted) OBJ_TAINT(result);