mirror of
https://github.com/gin-gonic/gin.git
synced 2025-10-14 12:12:12 +08:00
Do not QueryEscape cookies
This commit is contained in:
parent
9c081de9cd
commit
7b9bca9cef
@ -946,7 +946,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,
|
||||
@ -965,8 +965,7 @@ func (c *Context) Cookie(name string) (string, error) {
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
val, _ := url.QueryUnescape(cookie.Value)
|
||||
return val, nil
|
||||
return cookie.Value, nil
|
||||
}
|
||||
|
||||
// Render writes the response headers and calls render.Render to render data.
|
||||
|
@ -685,6 +685,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("GET", "/get", nil)
|
||||
|
Loading…
x
Reference in New Issue
Block a user