diff --git a/helpers.go b/helpers.go index 9774b5dffce..dfa9f1805bf 100644 --- a/helpers.go +++ b/helpers.go @@ -169,7 +169,7 @@ func readContent(rf io.ReaderFrom, name string) (int64, error) { // Non-ASCII bytes are encoded as well so the result is always ASCII. func (app *App) quoteString(raw string) string { bb := bytebufferpool.Get() - quoted := app.toString(fasthttp.AppendQuotedArg(bb.B, app.toBytes(raw))) + quoted := string(fasthttp.AppendQuotedArg(bb.B, app.toBytes(raw))) bytebufferpool.Put(bb) return quoted } @@ -177,7 +177,7 @@ func (app *App) quoteString(raw string) string { // quoteRawString escapes only characters that need quoting according to // https://www.rfc-editor.org/rfc/rfc9110#section-5.6.4 so the result may // contain non-ASCII bytes. -func (app *App) quoteRawString(raw string) string { +func (*App) quoteRawString(raw string) string { const hex = "0123456789ABCDEF" bb := bytebufferpool.Get() defer bytebufferpool.Put(bb) @@ -205,7 +205,7 @@ func (app *App) quoteRawString(raw string) string { } } - return app.toString(bb.B) + return string(bb.B) } // isASCII reports whether the provided string contains only ASCII characters. diff --git a/helpers_test.go b/helpers_test.go index 4b2ee3b6ec2..75a74cbda9e 100644 --- a/helpers_test.go +++ b/helpers_test.go @@ -1667,6 +1667,32 @@ func Test_App_quoteRawString(t *testing.T) { } } +func Test_App_quoteString_DetachesFromPooledBuffer(t *testing.T) { + t.Parallel() + + app := New() + + first := app.quoteString("a b") + second := app.quoteString("x y") + + require.Equal(t, "a+b", first) + require.Equal(t, "x+y", second) + require.Equal(t, "a+b", first) +} + +func Test_App_quoteRawString_DetachesFromPooledBuffer(t *testing.T) { + t.Parallel() + + app := New() + + first := app.quoteRawString(`A\B`) + second := app.quoteRawString(`C"D`) + + require.Equal(t, `A\\B`, first) + require.Equal(t, `C\"D`, second) + require.Equal(t, `A\\B`, first) +} + func TestStoreInContext(t *testing.T) { t.Parallel()