diff options
author | nobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2017-01-11 02:31:02 +0000 |
---|---|---|
committer | nobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2017-01-11 02:31:02 +0000 |
commit | cd463d1551bbacae2d1cc60c729f7d2121b4bbc0 (patch) | |
tree | 19bea7fb141873f9264f9b47ec7bbdacf5283862 /string.c | |
parent | 32f7ad36130eb97df6cae2c9e908b8556134e60a (diff) | |
download | ruby-cd463d1551bbacae2d1cc60c729f7d2121b4bbc0.tar.gz |
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/trunk@57304 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'string.c')
-rw-r--r-- | string.c | 14 |
1 files changed, 9 insertions, 5 deletions
@@ -9206,9 +9206,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 (ENC_CODERANGE_CLEAN_P(cr)) return Qnil; @@ -9232,9 +9238,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)) { @@ -9345,9 +9350,8 @@ 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 (rb_block_given_p()) { + if (!replen) { rep = NULL; - replen = 0; } else if (!NIL_P(repl)) { rep = RSTRING_PTR(repl); |