Parse ParamBool case-insensitively (#1151)

This commit is contained in:
Steve Richter 2021-06-04 23:37:01 -04:00 committed by GitHub
parent bebfe296a5
commit 65ccd4c99d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 6 additions and 2 deletions

View File

@ -84,7 +84,7 @@ func ParamInts(r *http.Request, param string) []int {
}
func ParamBool(r *http.Request, param string, def bool) bool {
p := ParamString(r, param)
p := strings.ToLower(ParamString(r, param))
if p == "" {
return def
}

View File

@ -147,7 +147,7 @@ var _ = Describe("Request Helpers", func() {
Describe("ParamBool", func() {
Context("value is true", func() {
BeforeEach(func() {
r = httptest.NewRequest("GET", "/ping?b=true&c=on&d=1", nil)
r = httptest.NewRequest("GET", "/ping?b=true&c=on&d=1&e=True", nil)
})
It("parses 'true'", func() {
@ -161,6 +161,10 @@ var _ = Describe("Request Helpers", func() {
It("parses '1'", func() {
Expect(ParamBool(r, "d", false)).To(BeTrue())
})
It("parses 'True'", func() {
Expect(ParamBool(r, "e", false)).To(BeTrue())
})
})
Context("value is false", func() {