mirror of
https://github.com/valyala/fasthttp.git
synced 2026-06-15 16:07:51 +03:00
Properly encode cookie without name
This commit is contained in:
@@ -7,8 +7,10 @@ import (
|
||||
func appendCookieBytes(dst []byte, cookies []argsKV) []byte {
|
||||
for i, n := 0, len(cookies); i < n; i++ {
|
||||
kv := &cookies[i]
|
||||
dst = appendQuotedArg(dst, kv.key)
|
||||
dst = append(dst, '=')
|
||||
if len(kv.key) > 0 {
|
||||
dst = appendQuotedArg(dst, kv.key)
|
||||
dst = append(dst, '=')
|
||||
}
|
||||
dst = appendQuotedArg(dst, kv.value)
|
||||
if i+1 < n {
|
||||
dst = append(dst, ';', ' ')
|
||||
|
||||
+6
-6
@@ -8,11 +8,11 @@ import (
|
||||
func TestParseCookies(t *testing.T) {
|
||||
testParseCookies(t, "", "")
|
||||
testParseCookies(t, "=", "")
|
||||
testParseCookies(t, "foo", "=foo")
|
||||
testParseCookies(t, "=foo", "=foo")
|
||||
testParseCookies(t, "foo", "foo")
|
||||
testParseCookies(t, "=foo", "foo")
|
||||
testParseCookies(t, "bar=", "bar=")
|
||||
testParseCookies(t, "xxx=aa;bb=c; d; ;;e=g", "xxx=aa; bb=c; =d; e=g")
|
||||
testParseCookies(t, "a;b;c; d=1;d=2", "=c; d=2")
|
||||
testParseCookies(t, "xxx=aa;bb=c; =d; ;;e=g", "xxx=aa; bb=c; d; e=g")
|
||||
testParseCookies(t, "a;b;c; d=1;d=2", "c; d=2")
|
||||
testParseCookies(t, " %D0%B8%D0%B2%D0%B5%D1%82=a%20b%3Bc ;s%20s=aaa ", "%D0%B8%D0%B2%D0%B5%D1%82=a%20b%3Bc; s%20s=aaa")
|
||||
}
|
||||
|
||||
@@ -26,9 +26,9 @@ func testParseCookies(t *testing.T, s, expectedS string) {
|
||||
}
|
||||
|
||||
func TestAppendCookieBytes(t *testing.T) {
|
||||
testAppendCookieBytes(t, "=", "=")
|
||||
testAppendCookieBytes(t, "=", "")
|
||||
testAppendCookieBytes(t, "foo=", "foo=")
|
||||
testAppendCookieBytes(t, "=bar", "=bar")
|
||||
testAppendCookieBytes(t, "=bar", "bar")
|
||||
testAppendCookieBytes(t, "привет=a b;c&s s=aaa", "%D0%BF%D1%80%D0%B8%D0%B2%D0%B5%D1%82=a%20b%3Bc; s%20s=aaa")
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user