Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use bytesize to write number of bytes in Marshal.dump #2392

Merged
merged 1 commit into from
Dec 15, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading