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

Remove whitespace between parameter=value and ; in headers #195

Merged
merged 3 commits into from Jun 9, 2021

Conversation

demofrager
Copy link
Contributor

This is a fix for the problem of PR: 193

Sorry for taking over, but I really need the fix :(

Let me know if there is anything you would like me to change.

Thanks for the package.

header.go Outdated
@@ -308,6 +308,10 @@ func fixMangledMediaType(mtype string, sep rune) string {
// Only terminate with semicolon if not the last parameter and if it doesn't already have a
// semicolon.
if i != len(parts)-1 && !strings.HasSuffix(mtype, ";") {
// Remove whitespace between parameter=value and ;
for strings.HasSuffix(mtype, " ") || strings.HasSuffix(mtype, "\t") {
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

https://staticcheck.io/docs/checks#S1017 suggests we replace this check and slice with two calls to strings.TrimSuffix

I also wonder if it would be better to use TrimRight, as your implementation will only remove a single trailing whitespace character.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think TrimRight is a better approach. It removes everything in the cutset. No need for 2 TrimSuffix calls.

@jhillyerd
Copy link
Owner

Looks good, thanks!

@jhillyerd jhillyerd merged commit 8b689f5 into jhillyerd:master Jun 9, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants