deepCopyTags preserves nil tags slice
This commit is contained in:
@@ -41,6 +41,9 @@ func (v ValidatedEvent) Event() Event {
|
||||
}
|
||||
|
||||
func deepCopyTags(tags []Tag) []Tag {
|
||||
if tags == nil {
|
||||
return nil
|
||||
}
|
||||
cp := make([]Tag, len(tags))
|
||||
for i, tag := range tags {
|
||||
tagcp := make(Tag, len(tag))
|
||||
|
||||
@@ -135,6 +135,22 @@ func TestValidatedEventTagsImmutability(t *testing.T) {
|
||||
first[0][0] = "z"
|
||||
assert.Equal(t, "a", second[0][0])
|
||||
})
|
||||
|
||||
t.Run("nil tags remain nil", func(t *testing.T) {
|
||||
nil_tags_event := Event{
|
||||
ID: testEvent.ID,
|
||||
PubKey: testEvent.PubKey,
|
||||
CreatedAt: testEvent.CreatedAt,
|
||||
Kind: testEvent.Kind,
|
||||
Tags: nil,
|
||||
Content: testEvent.Content,
|
||||
Sig: testEvent.Sig,
|
||||
}
|
||||
ve, err := NewValidatedEvent(nil_tags_event)
|
||||
assert.NoError(t, err)
|
||||
assert.Nil(t, ve.Tags())
|
||||
assert.Nil(t, ve.Event().Tags)
|
||||
})
|
||||
}
|
||||
|
||||
func TestValidatedEventEventImmutability(t *testing.T) {
|
||||
|
||||
Reference in New Issue
Block a user