Skip to content

Commit 08c65d4

Browse files
k77ch7enebo
authored andcommitted
fix GH-2896 on master
1 parent 74892a4 commit 08c65d4

File tree

2 files changed

+23
-4
lines changed

2 files changed

+23
-4
lines changed

core/src/main/java/org/jruby/RubySymbol.java

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -270,8 +270,15 @@ private final IRubyObject inspect19(Ruby runtime) {
270270

271271
RubyString str = RubyString.newString(runtime, result);
272272
// TODO: 1.9 rb_enc_symname_p
273-
if (isPrintable() && isSymbolName19(symbol)) return str;
274-
273+
Encoding resenc = runtime.getDefaultInternalEncoding();
274+
if (resenc == null) {
275+
resenc = runtime.getDefaultExternalEncoding();
276+
}
277+
278+
if (isPrintable() && (resenc.equals(symbolBytes.getEncoding()) || str.isAsciiOnly()) && isSymbolName19(symbol)) {
279+
return str;
280+
}
281+
275282
str = (RubyString)str.inspect19();
276283
ByteList bytes = str.getByteList();
277284
bytes.set(0, ':');
@@ -512,11 +519,11 @@ public int getLine() {
512519
}
513520

514521
private static boolean isIdentStart(char c) {
515-
return ((c >= 'a' && c <= 'z')|| (c >= 'A' && c <= 'Z') || c == '_');
522+
return ((c >= 'a' && c <= 'z')|| (c >= 'A' && c <= 'Z') || c == '_' || !(c < 128));
516523
}
517524

518525
private static boolean isIdentChar(char c) {
519-
return ((c >= 'a' && c <= 'z') || (c >= '0' && c <= '9') || (c >= 'A' && c <= 'Z') || c == '_');
526+
return ((c >= 'a' && c <= 'z') || (c >= '0' && c <= '9') || (c >= 'A' && c <= 'Z') || c == '_' || !(c < 128));
520527
}
521528

522529
private static boolean isIdentifier(String s) {
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
# encoding: utf-8
2+
3+
# https://github.com/jruby/jruby/issues/2896
4+
if RUBY_VERSION > '1.9'
5+
describe 'Symbol#inspect' do
6+
it 'returns correct value' do
7+
:"Ãa1".inspect.should == ":Ãa1"
8+
:"a1".inspect.should == ":a1"
9+
:"1".inspect.should == ":\"1\""
10+
end
11+
end
12+
end

0 commit comments

Comments
 (0)