Skip to content

Commit

Permalink
use a default content-type if only media parameters are present (#140)
Browse files Browse the repository at this point in the history
  • Loading branch information
requaos authored and jhillyerd committed Dec 23, 2019
1 parent f9d5121 commit 3f81043
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 0 deletions.
5 changes: 5 additions & 0 deletions header.go
Original file line number Diff line number Diff line change
Expand Up @@ -277,6 +277,11 @@ func fixMangledMediaType(mtype, sep string) string {
}
parts := strings.Split(mtype, sep)
mtype = ""
if strings.Contains(parts[0], "=") {
// A parameter pair at this position indicates we are missing a content-type.
parts[0] = fmt.Sprintf("%s%s %s", ctAppOctetStream, sep, parts[0])
parts = strings.Split(strings.Join(parts, sep), sep)
}
for i, p := range parts {
switch i {
case 0:
Expand Down
5 changes: 5 additions & 0 deletions header_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -214,6 +214,11 @@ func TestFixMangledMediaType(t *testing.T) {
sep: ";",
want: ctPlaceholder + "; name=\"file.two\"",
},
{
input: "charset=binary; name=\"logoleft.jpg\"",
sep: ";",
want: "application/octet-stream; charset=binary; name=\"logoleft.jpg\"",
},
{
input: "one/two;iso-8859-1",
sep: ";",
Expand Down

0 comments on commit 3f81043

Please sign in to comment.