Merge pull request #4740 from zh199225/develop

set a default value "/" for "Path" in the Cookie function when there is not parameter "Path" or the parameter is ""
This commit is contained in:
Ming Deng 2021-08-20 17:53:38 +08:00 committed by GitHub
commit 2ba502538a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 4 additions and 3 deletions

View File

@ -60,6 +60,7 @@
- fix bug:reflect.ValueOf(nil) in getFlatParams [4715](https://github.com/beego/beego/pull/4715) - fix bug:reflect.ValueOf(nil) in getFlatParams [4715](https://github.com/beego/beego/pull/4715)
- Fix 4736: set a fixed value "/" to the "Path" of "_xsrf" cookie. [4736](https://github.com/beego/beego/issues/4735) - Fix 4736: set a fixed value "/" to the "Path" of "_xsrf" cookie. [4736](https://github.com/beego/beego/issues/4735)
- Fix 4734: do not reset id in Delete function. [4738](https://github.com/beego/beego/pull/4738) - Fix 4734: do not reset id in Delete function. [4738](https://github.com/beego/beego/pull/4738)
- Fix 4739: set a default value "/" for "Path" in the Cookie function when there is not parameter "Path" or the parameter is "". [4739](https://github.com/beego/beego/issues/4739)
## Fix Sonar ## Fix Sonar

View File

@ -118,13 +118,13 @@ func (output *BeegoOutput) Cookie(name string, value string, others ...interface
// can use nil skip set // can use nil skip set
// default "/" // default "/"
tmpPath := "/"
if len(others) > 1 { if len(others) > 1 {
if v, ok := others[1].(string); ok && len(v) > 0 { 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 // default empty
if len(others) > 2 { if len(others) > 2 {