Skip to content

Commit

Permalink
feat: skip empty parameters (#313)
Browse files Browse the repository at this point in the history
  • Loading branch information
milankonir committed Dec 12, 2023
1 parent ea70bfe commit 54fdf4d
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 0 deletions.
6 changes: 6 additions & 0 deletions mediatype/mediatype.go
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,12 @@ func fixMangledMediaType(mtype string, sep rune) string {
p = coding.RFC2047Decode(p)

pair := strings.SplitAfter(p, "=")

if strings.TrimSpace(pair[0]) == "=" {
// Ignore unnamed parameters.
continue
}

if strings.Contains(mtype, strings.TrimSpace(pair[0])) {
// Ignore repeated parameters.
continue
Expand Down
6 changes: 6 additions & 0 deletions mediatype/mediatype_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,12 @@ func TestFixMangledMediaType(t *testing.T) {
sep: ';',
want: `image/png; name="abc.png"`,
},
{
// Removes empty parameters in the middle
input: `Content-Type: text/html; =""; charset=""`,
sep: ';',
want: `Content-Type: text/html; charset=""`,
},
{
input: "application/octet-stream;=?UTF-8?B?bmFtZT0iw7DCn8KUwoo=?=You've got a new voice miss call.msg",
sep: ';',
Expand Down

0 comments on commit 54fdf4d

Please sign in to comment.