Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

strings.TrimLeft is used instead of TrimPrefix #2406

Open
3 of 4 tasks
GrosQuildu opened this issue Apr 18, 2023 · 0 comments
Open
3 of 4 tasks

strings.TrimLeft is used instead of TrimPrefix #2406

GrosQuildu opened this issue Apr 18, 2023 · 0 comments

Comments

@GrosQuildu
Copy link

Please fill out the issue checklist below and provide ALL the requested information.

  • I reviewed open and closed github issues that may be related to my problem.
  • 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=1 to help debug the issue.
  • 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.

func getFilenameFromHeader(h string) string {
if h == "" {
return ""
}
contents := strings.Split(h, ";")
for _, content := range contents {
if strings.Contains(content, "filename=") {
content = strings.TrimSpace(content)
name := strings.TrimLeft(content, "filename=")
return strings.Trim(name, `"`)
}
}
return ""
}

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"},

"Content-Disposition": []string{"attachment; filename=header.zip"},

and line below to Expect(name).To(Equal("ameno.zip"))

Expect(name).To(Equal("header.zip"))

will make the test fail.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants