Skip to content

Commit

Permalink
remove <!DOCTYPE tag in bad content types
Browse files Browse the repository at this point in the history
  • Loading branch information
Deepak Prabhakara committed Jan 15, 2017
1 parent 018e29f commit 3644cf8
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 0 deletions.
6 changes: 6 additions & 0 deletions part.go
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,12 @@ func parseMediaType(ctype string) (string, map[string]string, error) {
}
}()
if err != nil {
// check if ctype contains <!DOCTYPE tag and remove it
dtIdx := strings.Index(ctype, "<!DOCTYPE")
if dtIdx > -1 {
ctype = ctype[0:dtIdx]
}

// Small hack to remove harmless charset duplicate params
mctype := parseBadContentType(ctype, ";")
mtype, mparams, err = mime.ParseMediaType(mctype)
Expand Down
4 changes: 4 additions & 0 deletions part_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -241,6 +241,10 @@ func TestBadContentTypes(t *testing.T) {
"mtype": "inline",
"filename": "",
},
`text/html; charset="iso-8859-1"<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">`: map[string]string{
"mtype": "text/html",
"charset": "iso-8859-1",
},
}

for ctype, m := range bctypes {
Expand Down

0 comments on commit 3644cf8

Please sign in to comment.