Skip to content
Permalink
Browse files
Fixed #2388: String#b improperly updates encoding of source string.
  • Loading branch information
nirvdrum committed Dec 24, 2014
1 parent ecee892 commit 4e4073299cd2199116e8396f6984d7ace0063cf9
Showing with 7 additions and 6 deletions.
  1. +7 −6 core/src/main/java/org/jruby/RubyString.java
@@ -5963,8 +5963,11 @@ public IRubyObject encode(ThreadContext context, IRubyObject toEncoding,

@JRubyMethod
public IRubyObject force_encoding(ThreadContext context, IRubyObject enc) {
return force_encoding(context, context.runtime.getEncodingService().getEncodingFromObject(enc));
}

private IRubyObject force_encoding(ThreadContext context, Encoding encoding) {
modify19();
Encoding encoding = context.runtime.getEncodingService().getEncodingFromObject(enc);
associateEncoding(encoding);
clearCodeRange();
return this;
@@ -5982,11 +5985,9 @@ public IRubyObject ascii_only_p(ThreadContext context) {

@JRubyMethod
public IRubyObject b(ThreadContext context) {
Encoding encoding = ASCIIEncoding.INSTANCE;
RubyString dup = (RubyString)dup();
dup.associateEncoding(encoding);
dup.clearCodeRange();
return dup;
RubyString dup = strDup(context.runtime);

return dup.force_encoding(context, ASCIIEncoding.INSTANCE);
}

// MRI: str_scrub arity 0

0 comments on commit 4e40732

Please sign in to comment.