Skip to content

Commit

Permalink
Fix jrubyGH-2182 on jruby-1_7
Browse files Browse the repository at this point in the history
  • Loading branch information
k77ch7 committed Dec 15, 2014
1 parent 53ca557 commit 4d99577
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 1 deletion.
9 changes: 8 additions & 1 deletion core/src/main/java/org/jruby/RubyStruct.java
Expand Up @@ -556,7 +556,14 @@ private IRubyObject inspectStruct(final ThreadContext context) {
// FIXME: MRI has special case for constants here
buffer.append(RubyString.objAsString(context, member.eltInternal(i)).getByteList());
buffer.append('=');
buffer.append(inspect(context, values[i]).getByteList());
RubyString valueInspect = inspect(context, values[i]);
if (valueInspect.isAsciiOnly()) {
buffer.append(valueInspect.getByteList());
} else {
String str = ByteList.decode(buffer.bytes(), buffer.getEncoding().getCharsetName());
str += valueInspect;
buffer = new ByteList(str.getBytes(), valueInspect.getByteList().getEncoding());
}
}

buffer.append('>');
Expand Down
20 changes: 20 additions & 0 deletions spec/regression/GH-2182_struct_inspect_has_ascii_encoding_spec.rb
@@ -0,0 +1,20 @@
# -*- encoding: utf-8 -*-

# https://github.com/jruby/jruby/issues/2182
if RUBY_VERSION > '1.9'
describe 'Struct#inspect' do
it 'returns correct value' do
s1 = Struct.new(:aa).new("ΆἅἇἈ")
s1.inspect.should == "#<struct aa=\"ΆἅἇἈ\">"
s1.inspect.encoding.should == Encoding::UTF_8

s2 = Struct.new(:a, :b).new("ΆἅἇἈ", "abc")
s2.inspect.should == "#<struct a=\"ΆἅἇἈ\", b=\"abc\">"
s2.inspect.encoding.should == Encoding::UTF_8

s3 = Struct.new(:b).new("abc")
s3.inspect.should == "#<struct b=\"abc\">"
s3.inspect.encoding.should == Encoding::ASCII_8BIT
end
end
end

0 comments on commit 4d99577

Please sign in to comment.