diff --git a/context.go b/context.go index c724daf3..5646587d 100644 --- a/context.go +++ b/context.go @@ -1017,7 +1017,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, diff --git a/context_test.go b/context_test.go index 5b63a647..de8cc3b0 100644 --- a/context_test.go +++ b/context_test.go @@ -873,6 +873,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)