Skip to content

Commit

Permalink
Showing 2 changed files with 23 additions and 4 deletions.
15 changes: 11 additions & 4 deletions core/src/main/java/org/jruby/RubySymbol.java
Original file line number Diff line number Diff line change
@@ -270,8 +270,15 @@ private final IRubyObject inspect19(Ruby runtime) {

RubyString str = RubyString.newString(runtime, result);
// TODO: 1.9 rb_enc_symname_p
if (isPrintable() && isSymbolName19(symbol)) return str;

Encoding resenc = runtime.getDefaultInternalEncoding();
if (resenc == null) {
resenc = runtime.getDefaultExternalEncoding();
}

if (isPrintable() && (resenc.equals(symbolBytes.getEncoding()) || str.isAsciiOnly()) && isSymbolName19(symbol)) {
return str;
}

str = (RubyString)str.inspect19();
ByteList bytes = str.getByteList();
bytes.set(0, ':');
@@ -512,11 +519,11 @@ public int getLine() {
}

private static boolean isIdentStart(char c) {
return ((c >= 'a' && c <= 'z')|| (c >= 'A' && c <= 'Z') || c == '_');
return ((c >= 'a' && c <= 'z')|| (c >= 'A' && c <= 'Z') || c == '_' || !(c < 128));
}

private static boolean isIdentChar(char c) {
return ((c >= 'a' && c <= 'z') || (c >= '0' && c <= '9') || (c >= 'A' && c <= 'Z') || c == '_');
return ((c >= 'a' && c <= 'z') || (c >= '0' && c <= '9') || (c >= 'A' && c <= 'Z') || c == '_' || !(c < 128));
}

private static boolean isIdentifier(String s) {
12 changes: 12 additions & 0 deletions spec/regression/GH-2896_symbol_inspect_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
# encoding: utf-8

# https://github.com/jruby/jruby/issues/2896
if RUBY_VERSION > '1.9'
describe 'Symbol#inspect' do
it 'returns correct value' do
:"Ãa1".inspect.should == ":Ãa1"
:"a1".inspect.should == ":a1"
:"1".inspect.should == ":\"1\""
end
end
end

0 comments on commit 08c65d4

Please sign in to comment.