[ruby-core:123623] [Ruby Bug#21658] Encoding objects are dumped with an encoding of US-ASCII
Issue #21658 has been reported by headius (Charles Nutter). ---------------------------------------- Bug #21658: Encoding objects are dumped with an encoding of US-ASCII https://bugs.ruby-lang.org/issues/21658 * Author: headius (Charles Nutter) * Status: Open * ruby -v: ruby 3.4.7 (2025-10-08 revision 7a5688e2a2) +PRISM [arm64-darwin24] * Backport: 3.2: UNKNOWN, 3.3: UNKNOWN, 3.4: UNKNOWN ---------------------------------------- All encodings get Marshal.dump'ed with an encoding instance variable: ``` $ cx ruby-3.4 ruby -e 'Encoding.constants.each { p Marshal.dump(Encoding.const_get(it)) }' "\x04\bIu:\rEncoding\x10MacJapanese\x06:\x06EF" "\x04\bIu:\rEncoding\x10MacJapanese\x06:\x06EF" "\x04\bIu:\rEncoding\rUS-ASCII\x06:\x06EF" "\x04\bIu:\rEncoding\rUS-ASCII\x06:\x06EF" "\x04\bIu:\rEncoding\x10MacJapanese\x06:\x06EF" "\x04\bIu:\rEncoding\nUTF-7\x06:\x06EF" "\x04\bIu:\rEncoding\nUTF-8\x06:\x06EF" "\x04\bIu:\rEncoding\nUTF-7\x06:\x06EF" ... ``` This despite the fact that an Encoding does not have an encoding: ``` $ cx ruby-3.4 ruby -e 'Encoding::UTF_8.encoding' -e:1:in '<main>': undefined method 'encoding' for an instance of Encoding (NoMethodError) ``` Compare with JRuby output: ``` $ cx jruby-10.0.2.0 ruby -e 'p Marshal.dump(Encoding::UTF_8)' "\x04\bu:\rEncoding\nUTF-8" ``` This extra instance variable data causes the output to be unloadable by JRuby, because an Encoding object cannot itself have an encoding: ``` $ cx jruby-10.0.2.0 ruby -e 'p Marshal.load("\x04\bIu:\rEncoding\nUTF-8\x06:\x06EF")' ArgumentError: UTF-8is not enc_capable load at org/jruby/RubyMarshal.java:165 <main> at -e:1 ``` This is reported as a JRuby issue here: https://github.com/jruby/jruby/issues/9050 Encoding should not marshal with an encoding it does not actually have. -- https://bugs.ruby-lang.org/
Issue #21658 has been updated by nobu (Nobuyoshi Nakada). Status changed from Open to Rejected That is not an instance variable of an `Encoding` instance, but the instance variable for the encoding of the name. ---------------------------------------- Bug #21658: Encoding objects are dumped with an encoding of US-ASCII https://bugs.ruby-lang.org/issues/21658#change-115016 * Author: headius (Charles Nutter) * Status: Rejected * ruby -v: ruby 3.4.7 (2025-10-08 revision 7a5688e2a2) +PRISM [arm64-darwin24] * Backport: 3.2: UNKNOWN, 3.3: UNKNOWN, 3.4: UNKNOWN ---------------------------------------- All encodings get Marshal.dump'ed with an encoding instance variable: ``` $ cx ruby-3.4 ruby -e 'Encoding.constants.each { p Marshal.dump(Encoding.const_get(it)) }' "\x04\bIu:\rEncoding\x10MacJapanese\x06:\x06EF" "\x04\bIu:\rEncoding\x10MacJapanese\x06:\x06EF" "\x04\bIu:\rEncoding\rUS-ASCII\x06:\x06EF" "\x04\bIu:\rEncoding\rUS-ASCII\x06:\x06EF" "\x04\bIu:\rEncoding\x10MacJapanese\x06:\x06EF" "\x04\bIu:\rEncoding\nUTF-7\x06:\x06EF" "\x04\bIu:\rEncoding\nUTF-8\x06:\x06EF" "\x04\bIu:\rEncoding\nUTF-7\x06:\x06EF" ... ``` This despite the fact that an Encoding does not have an encoding: ``` $ cx ruby-3.4 ruby -e 'Encoding::UTF_8.encoding' -e:1:in '<main>': undefined method 'encoding' for an instance of Encoding (NoMethodError) ``` Compare with JRuby output: ``` $ cx jruby-10.0.2.0 ruby -e 'p Marshal.dump(Encoding::UTF_8)' "\x04\bu:\rEncoding\nUTF-8" ``` This extra instance variable data causes the output to be unloadable by JRuby, because an Encoding object cannot itself have an encoding: ``` $ cx jruby-10.0.2.0 ruby -e 'p Marshal.load("\x04\bIu:\rEncoding\nUTF-8\x06:\x06EF")' ArgumentError: UTF-8is not enc_capable load at org/jruby/RubyMarshal.java:165 <main> at -e:1 ``` This is reported as a JRuby issue here: https://github.com/jruby/jruby/issues/9050 Encoding should not marshal with an encoding it does not actually have. -- https://bugs.ruby-lang.org/
participants (2)
-
headius (Charles Nutter) -
nobu (Nobuyoshi Nakada)