Skip to content

Commit

Permalink
Fix userdata re-use after Remove
Browse files Browse the repository at this point in the history
See also: #1298
  • Loading branch information
erikdubbelboer committed May 11, 2022
1 parent 7cc6f4c commit 9961079
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 1 deletion.
2 changes: 1 addition & 1 deletion userdata.go
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ func (d *userData) Remove(key string) {
kv := &args[i]
if string(kv.key) == key {
n--
args[i] = args[n]
args[i], args[n] = args[n], args[i]
args[n].value = nil
args = args[:n]
*d = args
Expand Down
15 changes: 15 additions & 0 deletions userdata_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -104,3 +104,18 @@ func TestUserDataDelete(t *testing.T) {
}

}

func TestUserDataSetAndRemove(t *testing.T) {
var (
u userData
shortKey = "[]"
longKey = "[ ]"
)

u.Set(shortKey, "")
u.Set(longKey, "")
u.Remove(shortKey)
u.Set(shortKey, "")
testUserDataGet(t, &u, []byte(shortKey), "")
testUserDataGet(t, &u, []byte(longKey), "")
}

0 comments on commit 9961079

Please sign in to comment.