Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions helpers.go
Original file line number Diff line number Diff line change
Expand Up @@ -169,15 +169,15 @@ 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
}

// 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)
Expand Down Expand Up @@ -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.
Expand Down
26 changes: 26 additions & 0 deletions helpers_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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()

Expand Down
Loading