mirror of https://github.com/gofiber/fiber.git
Remove logger
parent
33420cb64b
commit
320cee0400
38
ctx.go
38
ctx.go
|
@ -23,7 +23,6 @@ import (
|
||||||
"text/template"
|
"text/template"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/gofiber/fiber/v3/log"
|
|
||||||
"github.com/gofiber/utils/v2"
|
"github.com/gofiber/utils/v2"
|
||||||
"github.com/valyala/bytebufferpool"
|
"github.com/valyala/bytebufferpool"
|
||||||
"github.com/valyala/fasthttp"
|
"github.com/valyala/fasthttp"
|
||||||
|
@ -459,30 +458,27 @@ func (c *DefaultCtx) Cookies(key string, defaultValue ...string) string {
|
||||||
// It removes invalid characters from the cookie value, similar to how
|
// It removes invalid characters from the cookie value, similar to how
|
||||||
// Go's standard library handles cookie values.
|
// Go's standard library handles cookie values.
|
||||||
func (c *DefaultCtx) sanitizeCookieValue(v string) string {
|
func (c *DefaultCtx) sanitizeCookieValue(v string) string {
|
||||||
var result strings.Builder
|
// First, check if all characters are valid.
|
||||||
result.Grow(len(v))
|
valid := true
|
||||||
invalidChars := make(map[byte]struct{})
|
|
||||||
|
|
||||||
for i := 0; i < len(v); i++ {
|
for i := 0; i < len(v); i++ {
|
||||||
b := v[i]
|
if !c.validCookieValueByte(v[i]) {
|
||||||
if c.validCookieValueByte(b) {
|
valid = false
|
||||||
result.WriteByte(b)
|
break
|
||||||
} else {
|
|
||||||
invalidChars[b] = struct{}{}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
// If all characters are valid, return the original string.
|
||||||
if len(invalidChars) > 0 {
|
if valid {
|
||||||
var chars []string
|
|
||||||
for b := range invalidChars {
|
|
||||||
chars = append(chars, fmt.Sprintf("'%c'", b))
|
|
||||||
}
|
|
||||||
log.Warn("invalid byte(s) %s in Cookie.Value; dropping invalid bytes",
|
|
||||||
strings.Join(chars, ", "))
|
|
||||||
return result.String()
|
|
||||||
}
|
|
||||||
|
|
||||||
return v
|
return v
|
||||||
|
}
|
||||||
|
|
||||||
|
// Otherwise, build a sanitized string in a byte slice.
|
||||||
|
buf := make([]byte, 0, len(v))
|
||||||
|
for i := 0; i < len(v); i++ {
|
||||||
|
if c.validCookieValueByte(v[i]) {
|
||||||
|
buf = append(buf, v[i])
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return string(buf)
|
||||||
}
|
}
|
||||||
|
|
||||||
// validCookieValueByte reports whether b is a valid byte in a cookie value.
|
// validCookieValueByte reports whether b is a valid byte in a cookie value.
|
||||||
|
|
|
@ -12,7 +12,7 @@ import (
|
||||||
"github.com/stretchr/testify/require"
|
"github.com/stretchr/testify/require"
|
||||||
)
|
)
|
||||||
|
|
||||||
const CorrectKey = "specials: !$%,.#!?~`<>@$^*(){}[]|/123"
|
const CorrectKey = "specials: !$%,.#\"!?~`<>@$^*(){}[]|/\\123"
|
||||||
|
|
||||||
var testConfig = fiber.TestConfig{
|
var testConfig = fiber.TestConfig{
|
||||||
Timeout: 0,
|
Timeout: 0,
|
||||||
|
|
Loading…
Reference in New Issue