strings.TrimLeft is used instead of TrimPrefix
Please fill out the issue checklist below and provide ALL the requested information.
- [X] I reviewed open and closed github issues that may be related to my problem.
- [X] I tried updating to the latest version of the CF CLI to see if it fixed my problem.
- [ ] I attempted to run the command with
CF_TRACE=1to help debug the issue. - [X] I am reporting a bug that others will be able to reproduce.
Describe the bug and the command you saw an issue with
In the getFilenameFromHeader method the "filename=" string is a cutset (a set of characters) to be removed, and not a prefix.
https://github.com/cloudfoundry/cli/blob/b5a352a685bdafa86f1552870ace148ee5dd7137/cf/util/downloader/file_download.go#L90-L105
Fixed function should be like this:
func getFilenameFromHeader(h string) string {
if h == "" {
return ""
}
contents := strings.Split(h, ";")
for _, content := range contents {
content = strings.TrimSpace(content)
if strings.HasPrefix(content, "filename=") {
name := strings.TrimPrefix(content, "filename=")
return strings.Trim(name, `"`)
}
}
return ""
}
Exact Steps To Reproduce
Changing line below to "Content-Disposition": []string{"attachment; filename=ameno.zip"},
https://github.com/cloudfoundry/cli/blob/b5a352a685bdafa86f1552870ace148ee5dd7137/cf/util/downloader/file_download_test.go#L85
and line below to Expect(name).To(Equal("ameno.zip"))
https://github.com/cloudfoundry/cli/blob/b5a352a685bdafa86f1552870ace148ee5dd7137/cf/util/downloader/file_download_test.go#L111
will make the test fail.