New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
net/http: Request.Cookie returns first cookie when name is empty #53181
Comments
the same thing happened to me !! |
…hen cookie name is empty http.Cookie(name string) will return the first cookie when name is a empty string. since readCookies in file net/http/cookie.go at 247 will return all cookies when second parameter is a empty string and http.Cookie don`t check whether cookie name match the parameter. so solution is to check whether cookie name match the specific parameter. Fixes golang#53181
…hen cookie name is empty http.Cookie(name string) will return the first cookie when name is a empty string. since readCookies in file net/http/cookie.go at 247 will return all cookies when second parameter is a empty string and http.Cookie don`t check whether cookie name match the parameter. so solution is to check whether cookie name match the specific parameter. Fixes golang#53181
…hen cookie name is empty http.Cookie(name string) will return the first cookie when name is a empty string. since readCookies in file net/http/cookie.go at 247 will return all cookies when second parameter is a empty string and http.Cookie don`t check whether cookie name match the parameter. so solution is to check whether cookie name match the specific parameter. Fixes golang#53181
Change https://go.dev/cl/409754 mentions this issue: |
func (r *Request) Cookie(name string) (*Cookie, error) {
if name == "" {
return nil, ErrNoCookie
}
for _, c := range readCookies(r.Header, name) {
return c, nil
}
return nil, ErrNoCookie
} |
cc @neild |
I think cookie's lack of key is unreasonable and should be pointed out. |
Given that the current behavior is undocumented, surprising, and doesn't seem to be useful, I think |
…hen cookie name is empty http.Cookie(name string) will return the first cookie when name is a empty string. since readCookies in file net/http/cookie.go at 247 will return all cookies when second parameter is a empty string and http.Cookie don`t check whether cookie name match the parameter. so solution is to check whether cookie name match the specific parameter. Fixes golang#53181
…hen cookie name is empty Request.Cookie(name string) will return the first cookie when name is "". since readCookies in file net/http/cookie.go at line 247 will return all cookies when second parameter is a empty string and http.Cookie don`t check whether cookie name match the parameter. so solution is to return ErrNoCookie if cookie name is "". Fixes golang#53181
Request.Cookie(name string) will return the first cookie when cookie name is "". Since readCookies in file net/http/cookie.go at line 247 return all cookies when second parameter is a empty string. To fix it, Return ErrNoCookie from Request.Cookie(""), instead of the first cookie in the request. Fixes golang#53181 Change-Id: Ie623ca4c53da64ef7623a7863292a2d771f76832 GitHub-Last-Rev: 1a6903f GitHub-Pull-Request: golang#53183
Request.Cookie(name string) will return the first cookie when cookie name is "". Since readCookies in file net/http/cookie.go at line 247 return all cookies when second parameter is a empty string. To fix it, Return ErrNoCookie from Request.Cookie(""), instead of the first cookie in the request. Fixes golang#53181 Change-Id: Ie623ca4c53da64ef7623a7863292a2d771f76832 GitHub-Last-Rev: 1a6903f GitHub-Pull-Request: golang#53183
Request.Cookie(name string) will return the first cookie when cookie name is "". Since readCookies in file net/http/cookie.go at line 247 return all cookies when second parameter is a empty string. To fix it, Return ErrNoCookie from Request.Cookie(""), instead of the first cookie in the request. Fixes golang#53181 Change-Id: Ie623ca4c53da64ef7623a7863292a2d771f76832 GitHub-Last-Rev: 1a6903f GitHub-Pull-Request: golang#53183
What version of Go are you using (
go version
)?Does this issue reproduce with the latest release?
yes
What operating system and processor architecture are you using (
go env
)?go env
OutputWhat did you do?
see link blow
https://go.dev/play/p/svsT3co5Y_X
What did you expect to see?
it suppose to return http.ErrNoCookie
What did you see instead?
unexpected cookie
The text was updated successfully, but these errors were encountered: