Skip to content

Commit

Permalink
Use bytesize to write number of bytes in Marshal.dump
Browse files Browse the repository at this point in the history
Not the string size.
  • Loading branch information
herwinw committed Dec 15, 2024
1 parent 654d5d3 commit 0e98195
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 14 deletions.
20 changes: 7 additions & 13 deletions spec/core/marshal/dump_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -79,9 +79,7 @@

it "dumps a binary encoded Symbol" do
s = "\u2192".dup.force_encoding("binary").to_sym
NATFIXME 'dumps a binary encoded Symbol', exception: SpecFailedException do
Marshal.dump(s).should == "\x04\b:\b\xE2\x86\x92"
end
Marshal.dump(s).should == "\x04\b:\b\xE2\x86\x92"
end

it "dumps multiple Symbols sharing the same encoding" do
Expand Down Expand Up @@ -384,9 +382,7 @@ def _dump(level)

it "dumps a UTF-8 String" do
str = "\x6d\xc3\xb6\x68\x72\x65".dup.force_encoding("utf-8")
NATFIXME 'dumps a UTF-8 String', exception: SpecFailedException do
Marshal.dump(str).should == "\x04\bI\"\vm\xC3\xB6hre\x06:\x06ET"
end
Marshal.dump(str).should == "\x04\bI\"\vm\xC3\xB6hre\x06:\x06ET"
end

it "dumps a String in another encoding" do
Expand Down Expand Up @@ -452,15 +448,13 @@ def _dump(level)

it "dumps a UTF-8 Regexp" do
o = Regexp.new("".dup.force_encoding("utf-8"), Regexp::FIXEDENCODING)
NATFIXME 'dumps a UTF-8 Regexp', exception: SpecFailedException do
Marshal.dump(o).should == "\x04\bI/\x00\x10\x06:\x06ET"
Marshal.dump(o).should == "\x04\bI/\x00\x10\x06:\x06ET"

o = Regexp.new("a".dup.force_encoding("utf-8"), Regexp::FIXEDENCODING)
Marshal.dump(o).should == "\x04\bI/\x06a\x10\x06:\x06ET"
o = Regexp.new("a".dup.force_encoding("utf-8"), Regexp::FIXEDENCODING)
Marshal.dump(o).should == "\x04\bI/\x06a\x10\x06:\x06ET"

o = Regexp.new("\u3042".dup.force_encoding("utf-8"), Regexp::FIXEDENCODING)
Marshal.dump(o).should == "\x04\bI/\b\xE3\x81\x82\x10\x06:\x06ET"
end
o = Regexp.new("\u3042".dup.force_encoding("utf-8"), Regexp::FIXEDENCODING)
Marshal.dump(o).should == "\x04\bI/\b\xE3\x81\x82\x10\x06:\x06ET"
end

it "dumps a Regexp in another encoding" do
Expand Down
2 changes: 1 addition & 1 deletion src/marshal.rb
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ def write_bigint_bytes(value)

def write_string_bytes(value)
string = value.to_s
write_integer_bytes(string.length)
write_integer_bytes(string.bytesize)
write_bytes(string)
end

Expand Down

0 comments on commit 0e98195

Please sign in to comment.