Skip to content

Commit

Permalink
Port recent String#scrub fixes from MRI.
Browse files Browse the repository at this point in the history
  • Loading branch information
headius committed Jan 13, 2017
1 parent 1fc0604 commit 247afc4
Showing 1 changed file with 15 additions and 3 deletions.
18 changes: 15 additions & 3 deletions core/src/main/java/org/jruby/RubyString.java
Expand Up @@ -5556,9 +5556,16 @@ public IRubyObject strScrub(ThreadContext context, IRubyObject repl, Block block
IRubyObject buf = context.nil;
byte[] repBytes;
int rep;
int replen;
int replen = -1;
boolean tainted = false;

if (block.isGiven()) {
if (!repl.isNil()) {
throw runtime.newArgumentError("both of block and replacement given");
}
replen = 0;
}

if (cr == CR_7BIT || cr == CR_VALID)
return context.nil;

Expand Down Expand Up @@ -5695,7 +5702,12 @@ else if (MBCLEN_INVALID_P(ret)) {
int e = p + value.getRealSize();
int p1 = p;
int mbminlen = enc.minLength();
if (!repl.isNil()) {
if (block.isGiven()) {
repBytes = null;
rep = 0;
replen = 0;
}
else if (!repl.isNil()) {
repBytes = ((RubyString)repl).value.unsafeBytes();
rep = ((RubyString)repl).value.begin();
replen = ((RubyString)repl).value.getRealSize();
Expand Down Expand Up @@ -5756,7 +5768,7 @@ else if (MBCLEN_INVALID_P(ret)) {
((RubyString)buf).cat(repBytes, rep, replen);
}
else {
repl = block.yieldSpecific(context, RubyString.newString(runtime, pBytes, p, e-p, enc));
repl = block.yieldSpecific(context, RubyString.newString(runtime, pBytes, p, clen, enc));
repl = EncodingUtils.strCompatAndValid(context, repl, enc);
tainted |= repl.isTaint();
((RubyString)buf).cat((RubyString)repl);
Expand Down

0 comments on commit 247afc4

Please sign in to comment.