Always set a default value "/" for Cookie "Path"

When the URL is end with "/", and the parameter "Path" of SetCookie() Function is "", the "Path" of cookie that set in browser will not be the default value "/"., I think it's incorrect. When the URL is not end with "/", it's correct.
This commit is contained in:
zh199225 2021-08-20 09:23:03 +08:00 committed by GitHub
parent 29123f7d81
commit 326fea768a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -118,13 +118,13 @@ func (output *BeegoOutput) Cookie(name string, value string, others ...interface
// can use nil skip set
// default "/"
tmpPath := "/"
if len(others) > 1 {
if v, ok := others[1].(string); ok && len(v) > 0 {
fmt.Fprintf(&b, "; Path=%s", sanitizeValue(v))
tmpPath = sanitizeValue(v)
}
} else {
fmt.Fprintf(&b, "; Path=%s", "/")
}
fmt.Fprintf(&b, "; Path=%s", tmpPath)
// default empty
if len(others) > 2 {