mirror of
https://github.com/valyala/fasthttp.git
synced 2026-06-24 17:35:53 +03:00
Fix userdata re-use after Remove
See also: https://github.com/valyala/fasthttp/pull/1298
This commit is contained in:
+1
-1
@@ -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
|
||||
|
||||
@@ -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), "")
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user