fix: panic when no multipart/alternative children

This commit is contained in:
James Houlahan
2021-01-13 16:42:10 +01:00
parent 2f149eb545
commit 014c8af560
3 changed files with 10 additions and 3 deletions

View File

@ -329,8 +329,12 @@ func bestChoice(childParts []parser.Parts, preferredContentType string) parser.P
}
}
// Otherwise, choose the last one.
return childParts[len(childParts)-1]
// Otherwise, choose the last one, if it exists.
if len(childParts) > 0 {
return childParts[len(childParts)-1]
}
return parser.Parts{}
}
func allPartsHaveContentType(parts parser.Parts, contentType string) bool {