Skip to content

Commit 8fdb72e

Browse files
committed
Add spec for Marshal with multiple Symbols sharing the same encoding
* A complex case since serializing the encoding implies serializing Symbols recursively.
1 parent e840004 commit 8fdb72e

File tree

2 files changed

+32
-0
lines changed

2 files changed

+32
-0
lines changed

spec/ruby/core/marshal/dump_spec.rb

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,20 @@
7878
s = "\u2192".force_encoding("binary").to_sym
7979
Marshal.dump(s).should == "\x04\b:\b\xE2\x86\x92"
8080
end
81+
82+
it "dumps multiple Symbols sharing the same encoding" do
83+
# Note that the encoding is a link for the second Symbol
84+
symbol1 = "I:\t\xE2\x82\xACa\x06:\x06ET"
85+
symbol2 = "I:\t\xE2\x82\xACb\x06;\x06T"
86+
value = [
87+
"€a".force_encoding(Encoding::UTF_8).to_sym,
88+
"€b".force_encoding(Encoding::UTF_8).to_sym
89+
]
90+
Marshal.dump(value).should == "\x04\b[\a#{symbol1}#{symbol2}"
91+
92+
value = [*value, value[0]]
93+
Marshal.dump(value).should == "\x04\b[\b#{symbol1}#{symbol2};\x00"
94+
end
8195
end
8296

8397
describe "with an object responding to #marshal_dump" do

spec/ruby/core/marshal/shared/load.rb

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -399,6 +399,24 @@
399399
sym.should == s
400400
sym.encoding.should == Encoding::BINARY
401401
end
402+
403+
it "loads multiple Symbols sharing the same encoding" do
404+
# Note that the encoding is a link for the second Symbol
405+
symbol1 = "I:\t\xE2\x82\xACa\x06:\x06ET"
406+
symbol2 = "I:\t\xE2\x82\xACb\x06;\x06T"
407+
dump = "\x04\b[\a#{symbol1}#{symbol2}"
408+
value = Marshal.send(@method, dump)
409+
value.map(&:encoding).should == [Encoding::UTF_8, Encoding::UTF_8]
410+
expected = [
411+
"€a".force_encoding(Encoding::UTF_8).to_sym,
412+
"€b".force_encoding(Encoding::UTF_8).to_sym
413+
]
414+
value.should == expected
415+
416+
value = Marshal.send(@method, "\x04\b[\b#{symbol1}#{symbol2};\x00")
417+
value.map(&:encoding).should == [Encoding::UTF_8, Encoding::UTF_8, Encoding::UTF_8]
418+
value.should == [*expected, expected[0]]
419+
end
402420
end
403421

404422
describe "for a String" do

0 commit comments

Comments
 (0)