deepCopyTags preserves nil tags slice

This commit is contained in:
Jay
2026-05-22 10:08:10 -04:00
parent 12699a1630
commit c6145d6020
2 changed files with 19 additions and 0 deletions
+3
View File
@@ -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))
+16
View File
@@ -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) {