Skip to content

Commit

Permalink
fix panic when merging properties
Browse files Browse the repository at this point in the history
  • Loading branch information
jvitoroc committed Aug 16, 2024
1 parent 0c9e30d commit 354d53f
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 0 deletions.
3 changes: 3 additions & 0 deletions posthog.go
Original file line number Diff line number Diff line change
Expand Up @@ -230,6 +230,9 @@ func (c *client) Enqueue(msg Message) (err error) {
}
m.Properties["$active_feature_flags"] = featureKeys
}
if m.Properties == nil {
m.Properties = NewProperties()
}
m.Properties.Merge(c.DefaultEventProperties)
c.setLastCapturedEvent(m)
msg = m
Expand Down
26 changes: 26 additions & 0 deletions posthog_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -229,7 +229,33 @@ func ExampleCapture() {
// }
// ]
// }
}

func TestCaptureNoProperties(t *testing.T) {
defer func() {
// Ensure that the test doesn't panic.
if recover() != nil {
t.Error("shouldnt have panicked when merging properties into nil properties")
}
}()

_, server := mockServer()
defer server.Close()

client, _ := NewWithConfig("Csyjlnlun3OzyNJAafdlv", Config{
Endpoint: server.URL,
BatchSize: 1,
now: mockTime,
uid: mockId,
DefaultEventProperties: NewProperties().Set("service", "api"),
})
defer client.Close()

client.Enqueue(Capture{
Event: "Download",
DistinctId: "123456",
SendFeatureFlags: false,
})
}

func TestEnqueue(t *testing.T) {
Expand Down

0 comments on commit 354d53f

Please sign in to comment.