updated case to handle binary data

pull/3379/head
Anshul Sinha 2025-04-01 19:46:45 +05:30
parent 71c75ae998
commit 0d06e7ea90
1 changed files with 26 additions and 20 deletions

6
ctx.go
View File

@ -22,6 +22,7 @@ import (
"sync"
"text/template"
"time"
"unicode/utf8"
"github.com/gofiber/utils/v2"
"github.com/valyala/bytebufferpool"
@ -451,6 +452,11 @@ func (c *DefaultCtx) Cookie(cookie *Cookie) {
// Make copies or use the Immutable setting to use the value outside the Handler.
func (c *DefaultCtx) Cookies(key string, defaultValue ...string) string {
value := c.app.getString(c.fasthttp.Request.Header.Cookie(key))
// If the value looks like binary data, return it as-is
if len(value) > 0 && !utf8.ValidString(value) {
fmt.Println("Detected non-UTF8 cookie value, returning raw bytes")
return value
}
return defaultString(c.sanitizeCookieValue(value), defaultValue)
}