Skip to content

Commit

Permalink
Fix JRUBY-6272: Encoding exception running JRuby 1.6.5 (1.8 mode)
Browse files Browse the repository at this point in the history
Don't use cat19 for Hash#inspect in 1.8 mode.
  • Loading branch information
headius committed Dec 15, 2011
1 parent f497f26 commit d2c7065
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 3 deletions.
17 changes: 14 additions & 3 deletions src/org/jruby/RubyHash.java
Expand Up @@ -718,13 +718,24 @@ private IRubyObject inspectHash(final ThreadContext context) {
final boolean[] firstEntry = new boolean[1];

firstEntry[0] = true;
final boolean is19 = context.runtime.is1_9();
visitAll(new Visitor() {
public void visit(IRubyObject key, IRubyObject value) {
if (!firstEntry[0]) str.cat((byte)',').cat((byte)' ');

str.cat19(inspect(context, key));
str.cat((byte)'=').cat((byte)'>');
str.cat19(inspect(context, value));
RubyString inspectedKey = inspect(context, key);
RubyString inspectedValue = inspect(context, value);

if (is19) {
str.cat19(inspectedKey);
str.cat((byte)'=').cat((byte)'>');
str.cat19(inspectedValue);
} else {
str.cat(inspectedKey);
str.cat((byte)'=').cat((byte)'>');
str.cat(inspectedValue);
}

firstEntry[0] = false;
}
});
Expand Down
4 changes: 4 additions & 0 deletions src/org/jruby/RubyString.java
Expand Up @@ -1225,6 +1225,10 @@ public final RubyString cat19(RubyString str) {
return this;
}

public final RubyString cat(RubyString str) {
return cat(str.getByteList());
}

public final RubyString cat(ByteList str) {
modify(value.getRealSize() + str.getRealSize());
System.arraycopy(str.getUnsafeBytes(), str.getBegin(), value.getUnsafeBytes(), value.getBegin() + value.getRealSize(), str.getRealSize());
Expand Down

0 comments on commit d2c7065

Please sign in to comment.