Skip to content

Commit

Permalink
Touchup of RCF2047 mime attribute parameter decoding (#118)
Browse files Browse the repository at this point in the history
  • Loading branch information
requaos authored and jhillyerd committed Jan 24, 2019
1 parent 7e27711 commit a9ec2f8
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 1 deletion.
9 changes: 8 additions & 1 deletion header.go
Original file line number Diff line number Diff line change
Expand Up @@ -510,6 +510,13 @@ func rfc2047AttributeName(s string) string {
return s
}
pair := strings.SplitAfter(s, "?=")
pair[0] = decodeHeader(pair[0])
// lets assume that the attribute was encoded because of unicode characters being present
// then the attribute value should be quoted
keyValuePair := strings.SplitAfter(decodeHeader(pair[0]), "=")
// only quote the parameter value if it isn't already quoted
if !strings.HasPrefix(keyValuePair[1], "\"") {
keyValuePair[1] = fmt.Sprintf("\"%s", keyValuePair[1])
}
pair[0] = strings.Join(keyValuePair, "")
return strings.Join(pair, "")
}
5 changes: 5 additions & 0 deletions header_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -194,6 +194,11 @@ func TestFixMangledMediaType(t *testing.T) {
sep: ";",
want: "one/two; name=\"file.two\"",
},
{
input: "application/octet-stream; =?UTF-8?B?bmFtZT3DsMKfwpTCii5tc2c=?=",
sep: " ",
want: "application/octet-stream;name=\"🔊.msg",
},
{
input: "one/two name=\"file.two\" name=\"file.two\"",
sep: " ",
Expand Down

0 comments on commit a9ec2f8

Please sign in to comment.