Skip to content

Commit 907cb35

Browse files
andrykonchineregon
authored andcommitted
Fix Marshal and dumping String in a multibyte encoding
1 parent 5d39273 commit 907cb35

File tree

2 files changed

+26
-0
lines changed

2 files changed

+26
-0
lines changed

core/marshal/dump_spec.rb

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -193,6 +193,11 @@ def _dump(level)
193193
Marshal.dump(MarshalSpec::ClassWithOverriddenName).should == "\x04\bc)MarshalSpec::ClassWithOverriddenName"
194194
end
195195

196+
it "dumps a class with multibyte characters in name" do
197+
source_object = eval("MarshalSpec::MultibyteぁあぃいClass".force_encoding(Encoding::UTF_8))
198+
Marshal.dump(source_object).should == "\x04\bc,MarshalSpec::Multibyte\xE3\x81\x81\xE3\x81\x82\xE3\x81\x83\xE3\x81\x84Class"
199+
end
200+
196201
it "raises TypeError with an anonymous Class" do
197202
-> { Marshal.dump(Class.new) }.should raise_error(TypeError, /can't dump anonymous class/)
198203
end
@@ -211,6 +216,11 @@ def _dump(level)
211216
Marshal.dump(MarshalSpec::ModuleWithOverriddenName).should == "\x04\bc*MarshalSpec::ModuleWithOverriddenName"
212217
end
213218

219+
it "dumps a module with multibyte characters in name" do
220+
source_object = eval("MarshalSpec::MultibyteけげこごModule".force_encoding(Encoding::UTF_8))
221+
Marshal.dump(source_object).should == "\x04\bm-MarshalSpec::Multibyte\xE3\x81\x91\xE3\x81\x92\xE3\x81\x93\xE3\x81\x94Module"
222+
end
223+
214224
it "raises TypeError with an anonymous Module" do
215225
-> { Marshal.dump(Module.new) }.should raise_error(TypeError)
216226
end
@@ -673,6 +683,11 @@ def finalizer.noop(_)
673683
Marshal.dump(obj).should include("MarshalSpec::TimeWithOverriddenName")
674684
end
675685

686+
it "dumps a Time subclass with multibyte characters in name" do
687+
source_object = eval("MarshalSpec::MultibyteぁあぃいTime".force_encoding(Encoding::UTF_8))
688+
Marshal.dump(source_object).should == "\x04\bc+MarshalSpec::Multibyte\xE3\x81\x81\xE3\x81\x82\xE3\x81\x83\xE3\x81\x84Time"
689+
end
690+
676691
it "raises TypeError with an anonymous Time subclass" do
677692
-> { Marshal.dump(Class.new(Time).now) }.should raise_error(TypeError)
678693
end

core/marshal/fixtures/marshal_data.rb

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -262,6 +262,17 @@ def self.name
262262
end
263263
end
264264

265+
module_eval(<<~ruby.force_encoding(Encoding::UTF_8))
266+
class MultibyteぁあぃいClass
267+
end
268+
269+
module MultibyteけげこごModule
270+
end
271+
272+
class MultibyteぁあぃいTime < Time
273+
end
274+
ruby
275+
265276
DATA = {
266277
"nil" => [nil, "\004\b0"],
267278
"1..2" => [(1..2),

0 commit comments

Comments
 (0)