fix: content disposition filename parsing error (#613)
Co-authored-by: rick <LinuxSuRen@users.noreply.github.com>
This commit is contained in:
parent
accdb0e4ef
commit
430d9127c6
|
@ -55,7 +55,9 @@ type SimpleResponse struct {
|
|||
func (s SimpleResponse) getFileName() string {
|
||||
for k, v := range s.Header {
|
||||
if k == "Content-Disposition" {
|
||||
return strings.TrimSuffix(strings.TrimPrefix(v, `attachment; filename="`), `"`)
|
||||
v = strings.ReplaceAll(v, "attachment; filename=", "attachment;filename=")
|
||||
v = strings.ReplaceAll(v, `filename="`, "filename=")
|
||||
return strings.TrimSuffix(strings.TrimPrefix(v, `attachment;filename=`), `"`)
|
||||
}
|
||||
}
|
||||
return ""
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
Copyright 2023-2024 API Testing Authors.
|
||||
Copyright 2023-2025 API Testing Authors.
|
||||
|
||||
Licensed under the Apache License, Version 2.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
|
@ -59,5 +59,26 @@ func TestSimpleResponse(t *testing.T) {
|
|||
"Content-Disposition": `attachment; filename="a.txt"`,
|
||||
},
|
||||
}.getFileName())
|
||||
|
||||
// without space
|
||||
assert.Equal(t, "a.txt", SimpleResponse{
|
||||
Header: map[string]string{
|
||||
"Content-Disposition": `attachment;filename="a.txt"`,
|
||||
},
|
||||
}.getFileName())
|
||||
|
||||
// without quote
|
||||
assert.Equal(t, "a.txt", SimpleResponse{
|
||||
Header: map[string]string{
|
||||
"Content-Disposition": `attachment; filename=a.txt`,
|
||||
},
|
||||
}.getFileName())
|
||||
|
||||
// without quote and space
|
||||
assert.Equal(t, "a.txt", SimpleResponse{
|
||||
Header: map[string]string{
|
||||
"Content-Disposition": `attachment;filename=a.txt`,
|
||||
},
|
||||
}.getFileName())
|
||||
})
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue