
Issue #20009 has been updated by make_now_just (Hiroya Fujinami). In my opinion, we need to introduce a new format for dumping classes/modules correctly. Marshal uses `c` and `m` (`TYPE_CLASS` and `TYPE_MODULE`) as format prefixes currently, so the format is the following: ``` | 1 byte | ... | ... | | 'c'/'m' | path size | path name binary string | ``` And, this format lacks the encoding, then the bug is happened. To solve this issue, adding the encoding information to dump results is necessary, and introducing a new format seems a natural way to me. Therefore, a new format is the following (as a new type prefix is `K`): ``` | 1 byte | ... | | 'K' | a dump of the path symbol (`:`, `;`, or `I`) | ``` Such a format is used for dumping other kinds of objects. e.g., `o` and `S` (`TYPE_OBJECT` and `TYPE_STRUCT`). This idea does not break the backward compatibility, but we need to increment `MARSHAL_MINOR`. ---------------------------------------- Bug #20009: Marshal.load raises exception when load dumped class include non-ASCII https://bugs.ruby-lang.org/issues/20009#change-113192 * Author: ippachi (Kazuya Hatanaka) * Status: Open * ruby -v: ruby 3.2.2 (2023-03-30 revision e51014f9c0) [arm64-darwin22] * Backport: 3.0: UNKNOWN, 3.1: UNKNOWN, 3.2: UNKNOWN ---------------------------------------- ## Reproduction code ```ruby class Cクラス; end Marshal.load(Marshal.dump(Cクラス)) ``` ## Actual result ``` <internal:marshal>:34:in `load': undefined class/module C\xE3\x82\xAF\xE3\x83\xA9\xE3\x82\xB9 (ArgumentError) from marshal.rb:2:in `<main>' ``` ## Expected result Returns `Cクラス` ## Impacted area An exception is raised in Rails under the following conditions * minitest is used with default settings * Parallel execution with parallelize * test class names contain non-ASCII characters The default parallelization uses DRb, and Marshal is used inside DRb. ## Other After trying various things, I thought I could fix it by making `rb_path_to_class` support strings containing non-ASCII characters, but I couldn't find anything more than that. -- https://bugs.ruby-lang.org/