-
-
Notifications
You must be signed in to change notification settings - Fork 942
Closed
Milestone
Description
Actual Behavior
The Enumerator#inspect builds an ASCII-8 bit string, as opposed to what it does with other values:
# irb
irb(main):001:0> "Ä".inspect.encoding
=> #<Encoding:UTF-8>
irb(main):002:0> ["Ä"].inspect.encoding
=> #<Encoding:UTF-8>
irb(main):003:0> ["Ä"].each.inspect.encoding
=> #<Encoding:ASCII-8BIT>
This oddity in JRuby is quite inconvenient since it can easily cause an Encoding incompatibility when mixing this with other, UTF-8 encoded, strings (in custom #inspect methods, for instance):
irb(main):007:0> "#{["Ä"].each.inspect} / #{["Ä"].inspect}"
(irb):7:in `evaluate': incompatible encodings: ASCII-8BIT and UTF-8 (Encoding::CompatibilityError)
from org/jruby/RubyKernel.java:1143:in `eval'
from org/jruby/RubyKernel.java:1586:in `loop'
from org/jruby/RubyKernel.java:1292:in `catch'
from org/jruby/RubyKernel.java:1292:in `catch'
from /opt/jruby/lib/ruby/gems/shared/gems/irb-1.4.1/exe/irb:11:in `<main>'
from org/jruby/RubyKernel.java:1091:in `load'
from /opt/jruby/bin/irb:23:in `<main>'
Expected Behavior
The above contrasts with CRuby (Linux or Windows, any version between 2.7 and 3.2):
irb(main):001:0> ["Ä"].each.inspect.encoding
=> #<Encoding:UTF-8>
irb(main):002:0> "#{["Ä"].each.inspect} / #{["Ä"].inspect}"
=> "#<Enumerator: [\"Ä\"]:each> / [\"Ä\"]"
Environment Information
- JRuby version
root@8c5e900b8cf0:/opt# jruby -v
jruby 9.4.0.0 (3.1.0) 2022-11-23 95c0ec159f OpenJDK 64-Bit Server VM 25.352-b08 on 1.8.0_352-b08 +jit [x86_64-linux]
(from the official docker image jruby:9.4)
No JRUBY_OPTS, .jrubyrc, etc.
- Operating system and platform
# uname -a
Linux 8c5e900b8cf0 5.15.79.1-microsoft-standard-WSL2 #1 SMP Wed Nov 23 01:01:46 UTC 2022 x86_64 x86_64 x86_64 GNU/Linux
(but irrelevant for this issue)
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
No labels