Skip to content

Fix Hash#inspect of Symbol keys with non-ASCII encoding#9410

Merged
headius merged 1 commit into
jruby:masterfrom
sampokuokkanen:test_inspect
May 2, 2026
Merged

Fix Hash#inspect of Symbol keys with non-ASCII encoding#9410
headius merged 1 commit into
jruby:masterfrom
sampokuokkanen:test_inspect

Conversation

@sampokuokkanen

@sampokuokkanen sampokuokkanen commented May 2, 2026

Copy link
Copy Markdown
Contributor

isSymbolName was classifying names via a Java String built by RubyEncoding.decodeRaw (byte-as-Latin-1), losing multi-byte character grouping. Use the encoding-aware SymbolNameType when the string is not ASCII instead.

Re-enables TestHash#test_inspect; also drops a stale no-op exclude in TestHashOnly (no test_inspect method exists in that class).

@sampokuokkanen
sampokuokkanen marked this pull request as draft May 2, 2026 05:20
isSimpleName classified names via a Java String built by RubyEncoding.decodeRaw (byte-as-Latin-1), misclassifying multibyte characters. Use the existing isSymbolName(String) when ASCII and use the encoding-aware SymbolNameType when the encoding is not ASCII.

Re-enables TestHash#test_inspect; also drops a stale no-op exclude in TestHashOnly (no test_inspect method exists in that class).
@headius

headius commented May 2, 2026

Copy link
Copy Markdown
Member

Nice, thank you! Will wait to see how the tests shake out.

@headius headius added this to the JRuby 10.1.1.0 milestone May 2, 2026
@sampokuokkanen

Copy link
Copy Markdown
Contributor Author

Thanks! All the tests pass.

The challenging part was the differences between isSymbolName(String) and SymbolNameType. isSymbolName(String) has checks for global symbols like :$-w and other weird Ruby-stuff, but SymbolNameType (in IdUtil.determineSymbolNameType) sets these as OTHER. However SymbolNameType does work with non-ASCII characters.

So I guess a follow up PR would be to look more into SymbolNameType possibly miscategorizing symbols.

@sampokuokkanen
sampokuokkanen marked this pull request as ready for review May 2, 2026 13:20
@headius

headius commented May 2, 2026

Copy link
Copy Markdown
Member

Those methods are intended to mimic the same symbol classification logic in cruby but they have never been exactly the same and have diverged frequently. Every so often I run into a case where we need them to work correctly for some optimization or error check. This is a good step in the right direction.

@headius
headius merged commit 725c118 into jruby:master May 2, 2026
109 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants