Merge 929794596f18ada3ca5edfeae193c3b1a1c33823 into c3d1092b3b48addf6f9cd00fe274ec3bd14650eb

This commit is contained in:
Ludovico Cavedon 2025-10-11 21:19:01 +08:00 committed by GitHub
commit b0e286690f
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 8 additions and 1 deletions

View File

@ -1045,7 +1045,7 @@ func (c *Context) SetCookie(name, value string, maxAge int, path, domain string,
}
http.SetCookie(c.Writer, &http.Cookie{
Name: name,
Value: url.QueryEscape(value),
Value: value,
MaxAge: maxAge,
Path: path,
Domain: domain,

View File

@ -989,6 +989,13 @@ func TestContextSetCookiePathEmpty(t *testing.T) {
assert.Equal(t, "user=gin; Path=/; Domain=localhost; Max-Age=1; HttpOnly; Secure; SameSite=Lax", c.Writer.Header().Get("Set-Cookie"))
}
func TestContextSetCookieWithSpace(t *testing.T) {
c, _ := CreateTestContext(httptest.NewRecorder())
c.SetSameSite(http.SameSiteLaxMode)
c.SetCookie("user", "gin test", 1, "/", "localhost", true, true)
assert.Equal(t, "user=\"gin test\"; Path=/; Domain=localhost; Max-Age=1; HttpOnly; Secure; SameSite=Lax", c.Writer.Header().Get("Set-Cookie"))
}
func TestContextGetCookie(t *testing.T) {
c, _ := CreateTestContext(httptest.NewRecorder())
c.Request, _ = http.NewRequest(http.MethodGet, "/get", nil)