Fix userdata re-use after Remove

See also: https://github.com/valyala/fasthttp/pull/1298
This commit is contained in:
Erik Dubbelboer
2022-05-11 16:10:43 +02:00
parent 7cc6f4c513
commit 9961079196
2 changed files with 16 additions and 1 deletions
+1 -1
View File
@@ -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
+15
View File
@@ -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), "")
}