Remove logger

pull/3379/head
Juan Calderon-Perez 2025-04-01 08:22:40 -04:00 committed by GitHub
parent 33420cb64b
commit 320cee0400
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 21 additions and 25 deletions

38
ctx.go
View File

@ -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.

View File

@ -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,