summaryrefslogtreecommitdiff
path: root/string.c
diff options
context:
space:
mode:
authorusa <usa@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2017-03-25 15:36:01 +0000
committerusa <usa@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2017-03-25 15:36:01 +0000
commit8dc3d3fd54982480b3bf8ce2e0112bded800b982 (patch)
tree09333c5268c7dec211e7dd5807d9b0ece92de58c /string.c
parenta0f4f4369b4d5a04f163bfaa20c4360aba3cee29 (diff)
merge revision(s) 57302,57303,57304: [Backport #13119]
string.c: block for scrub with ASCII-incompatible * string.c (rb_enc_str_scrub): honor the given block with ASCII-incompatible encoding. [ruby-core:79039] [Bug #13120] string.c: yield invalid part * string.c (rb_enc_str_scrub): yield the invalid part only with ASCII-incompatible. [ruby-core:79039] [Bug #13120] string.c: replacement and block * string.c (rb_enc_str_scrub): only one of replacement and block is allowed. [ruby-core:79038] [Bug #13119] git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/branches/ruby_2_2@58091 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'string.c')
-rw-r--r--string.c18
1 files changed, 13 insertions, 5 deletions
diff --git a/string.c b/string.c
index d96c57c3a5..89723a08da 100644
--- a/string.c
+++ b/string.c
@@ -8345,9 +8345,15 @@ rb_enc_str_scrub(rb_encoding *enc, VALUE str, VALUE repl)
int encidx;
VALUE buf = Qnil;
const char *rep;
- long replen;
+ long replen = -1;
int tainted = 0;
+ if (rb_block_given_p()) {
+ if (!NIL_P(repl))
+ rb_raise(rb_eArgError, "both of block and replacement given");
+ replen = 0;
+ }
+
if (cr == ENC_CODERANGE_7BIT || cr == ENC_CODERANGE_VALID)
return Qnil;
@@ -8371,9 +8377,8 @@ rb_enc_str_scrub(rb_encoding *enc, VALUE str, VALUE repl)
const char *e = RSTRING_END(str);
const char *p1 = p;
int rep7bit_p;
- if (rb_block_given_p()) {
+ if (!replen) {
rep = NULL;
- replen = 0;
rep7bit_p = FALSE;
}
else if (!NIL_P(repl)) {
@@ -8484,7 +8489,10 @@ rb_enc_str_scrub(rb_encoding *enc, VALUE str, VALUE repl)
const char *e = RSTRING_END(str);
const char *p1 = p;
long mbminlen = rb_enc_mbminlen(enc);
- if (!NIL_P(repl)) {
+ if (!replen) {
+ rep = NULL;
+ }
+ else if (!NIL_P(repl)) {
rep = RSTRING_PTR(repl);
replen = RSTRING_LEN(repl);
}
@@ -8535,7 +8543,7 @@ rb_enc_str_scrub(rb_encoding *enc, VALUE str, VALUE repl)
rb_str_buf_cat(buf, rep, replen);
}
else {
- repl = rb_yield(rb_enc_str_new(p, e-p, enc));
+ 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));