Skip to content

Commit

Permalink
Fix Log::Metadata#dup crash with 2+ entries (#13369)
Browse files Browse the repository at this point in the history
  • Loading branch information
HertzDevil authored Apr 27, 2023
1 parent 8c76ff1 commit 35c0c73
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 0 deletions.
8 changes: 8 additions & 0 deletions spec/std/log/metadata_spec.cr
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,14 @@ describe Log::Metadata do
m({a: 1}).extend({} of Symbol => String).should_not be_empty
end

describe "#dup" do
it "creates a shallow copy" do
Log::Metadata.empty.dup.should eq(Log::Metadata.empty)
m({a: 1}).dup.should eq(m({a: 1}))
m({a: 1, b: 3}).dup.should eq(m({a: 1, b: 3}))
end
end

it "extend" do
m({a: 1}).extend({b: 2}).should eq(m({a: 1, b: 2}))
m({a: 1, b: 3}).extend({b: 2}).should eq(m({a: 1, b: 2}))
Expand Down
4 changes: 4 additions & 0 deletions src/log/metadata.cr
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,10 @@ class Log::Metadata
data
end

def dup : self
self
end

protected def setup(@parent : Metadata?, entries : NamedTuple | Hash)
@size = @overridden_size = entries.size
@max_total_size = @size + (@parent.try(&.max_total_size) || 0)
Expand Down

0 comments on commit 35c0c73

Please sign in to comment.