Skip to content

Commit

Permalink
Fixes #2528. RegexpError: invalid multibyte character
Browse files Browse the repository at this point in the history
  • Loading branch information
enebo committed Jan 28, 2015
1 parent effa2bc commit 331bae6
Showing 1 changed file with 8 additions and 22 deletions.
30 changes: 8 additions & 22 deletions core/src/main/java/org/jruby/RubyString.java
Expand Up @@ -2386,17 +2386,10 @@ public IRubyObject sub_bang19(ThreadContext context, IRubyObject arg0, Block blo
Ruby runtime = context.runtime;
frozenCheck();

final Regex pattern, prepared;
final RubyRegexp regexp;
if (arg0 instanceof RubyRegexp) {
regexp = (RubyRegexp)arg0;
pattern = regexp.getPattern();
prepared = regexp.preparePattern(this);
} else {
regexp = null;
pattern = getStringPattern19(runtime, arg0);
prepared = RubyRegexp.preparePattern(runtime, pattern, this);
}
RubyRegexp regexp = arg0 instanceof RubyRegexp ? (RubyRegexp) arg0 :
RubyRegexp.newRegexp(runtime, RubyRegexp.quote19(getStringForPattern(arg0).getByteList(), false), new RegexpOptions());
Regex pattern = regexp.getPattern();
Regex prepared = regexp.preparePattern(this);

if (block.isGiven()) return subBangIter19(runtime, context, pattern, prepared, null, block, regexp);
throw context.runtime.newArgumentError(1, 2);
Expand All @@ -2408,17 +2401,10 @@ public IRubyObject sub_bang19(ThreadContext context, IRubyObject arg0, IRubyObje
IRubyObject hash = TypeConverter.convertToTypeWithCheck(arg1, runtime.getHash(), "to_hash");
frozenCheck();

final Regex pattern, prepared;
final RubyRegexp regexp;
if (arg0 instanceof RubyRegexp) {
regexp = (RubyRegexp)arg0;
pattern = regexp.getPattern();
prepared = regexp.preparePattern(this);
} else {
regexp = null;
pattern = getStringPattern19(runtime, arg0);
prepared = RubyRegexp.preparePattern(runtime, pattern, this);
}
RubyRegexp regexp = arg0 instanceof RubyRegexp ? (RubyRegexp) arg0 :
RubyRegexp.newRegexp(runtime, RubyRegexp.quote19(getStringForPattern(arg0).getByteList(), false), new RegexpOptions());
Regex pattern = regexp.getPattern();
Regex prepared = regexp.preparePattern(this);

if (hash.isNil()) {
return subBangNoIter19(runtime, context, pattern, prepared, arg1.convertToString(), regexp);
Expand Down

0 comments on commit 331bae6

Please sign in to comment.