aboutsummaryrefslogtreecommitdiffstats
path: root/string.c
diff options
context:
space:
mode:
authornobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2015-12-17 05:16:27 +0000
committernobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2015-12-17 05:16:27 +0000
commit61c19c9d433f5855bc9e536bfa8d8c4e140157bd (patch)
treefb876e2ca3561d1e7423a57b03e02cd514364944 /string.c
parenteec8adb168b7a778ed1c087c93e73e470fd4ec64 (diff)
downloadruby-61c19c9d433f5855bc9e536bfa8d8c4e140157bd.tar.gz
string.c: infection
* string.c (rb_str_scrub): the result should be infected by the original string. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@53169 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'string.c')
-rw-r--r--string.c23
1 files changed, 13 insertions, 10 deletions
diff --git a/string.c b/string.c
index 2c8089b94c..4ab89a8e2f 100644
--- a/string.c
+++ b/string.c
@@ -8667,6 +8667,10 @@ rb_str_scrub(VALUE str, VALUE repl)
int cr = ENC_CODERANGE(str);
rb_encoding *enc;
int encidx;
+ VALUE buf = Qnil;
+ const char *rep;
+ long replen;
+ int tainted = 0;
if (ENC_CODERANGE_CLEAN_P(cr))
return Qnil;
@@ -8674,6 +8678,7 @@ rb_str_scrub(VALUE str, VALUE repl)
enc = STR_ENC_GET(str);
if (!NIL_P(repl)) {
repl = str_compat_and_valid(repl, enc);
+ tainted = OBJ_TAINTED_RAW(repl);
}
if (rb_enc_dummy_p(enc)) {
@@ -8690,10 +8695,7 @@ rb_str_scrub(VALUE str, VALUE repl)
const char *p = RSTRING_PTR(str);
const char *e = RSTRING_END(str);
const char *p1 = p;
- const char *rep;
- long replen;
int rep7bit_p;
- VALUE buf = Qnil;
if (rb_block_given_p()) {
rep = NULL;
replen = 0;
@@ -8759,6 +8761,7 @@ rb_str_scrub(VALUE str, VALUE repl)
else {
repl = rb_yield(rb_enc_str_new(p, clen, enc));
repl = str_compat_and_valid(repl, enc);
+ tainted |= OBJ_TAINTED_RAW(repl);
rb_str_buf_cat(buf, RSTRING_PTR(repl), RSTRING_LEN(repl));
if (ENC_CODERANGE(repl) == ENC_CODERANGE_VALID)
cr = ENC_CODERANGE_VALID;
@@ -8793,22 +8796,18 @@ rb_str_scrub(VALUE str, VALUE repl)
else {
repl = rb_yield(rb_enc_str_new(p, e-p, enc));
repl = str_compat_and_valid(repl, enc);
+ tainted |= OBJ_TAINTED_RAW(repl);
rb_str_buf_cat(buf, RSTRING_PTR(repl), RSTRING_LEN(repl));
if (ENC_CODERANGE(repl) == ENC_CODERANGE_VALID)
cr = ENC_CODERANGE_VALID;
}
}
- ENCODING_CODERANGE_SET(buf, rb_enc_to_index(enc), cr);
- return buf;
}
else {
/* ASCII incompatible */
const char *p = RSTRING_PTR(str);
const char *e = RSTRING_END(str);
const char *p1 = p;
- VALUE buf = Qnil;
- const char *rep;
- long replen;
long mbminlen = rb_enc_mbminlen(enc);
if (!NIL_P(repl)) {
rep = RSTRING_PTR(repl);
@@ -8863,6 +8862,7 @@ rb_str_scrub(VALUE str, VALUE repl)
else {
repl = rb_yield(rb_enc_str_new(p, e-p, enc));
repl = str_compat_and_valid(repl, enc);
+ tainted |= OBJ_TAINTED_RAW(repl);
rb_str_buf_cat(buf, RSTRING_PTR(repl), RSTRING_LEN(repl));
}
p += clen;
@@ -8889,12 +8889,15 @@ rb_str_scrub(VALUE str, VALUE repl)
else {
repl = rb_yield(rb_enc_str_new(p, e-p, enc));
repl = str_compat_and_valid(repl, enc);
+ tainted |= OBJ_TAINTED_RAW(repl);
rb_str_buf_cat(buf, RSTRING_PTR(repl), RSTRING_LEN(repl));
}
}
- ENCODING_CODERANGE_SET(buf, rb_enc_to_index(enc), ENC_CODERANGE_VALID);
- return buf;
+ cr = ENC_CODERANGE_VALID;
}
+ FL_SET_RAW(buf, tainted|OBJ_TAINTED_RAW(str));
+ ENCODING_CODERANGE_SET(buf, rb_enc_to_index(enc), cr);
+ return buf;
}
/*