aboutsummaryrefslogtreecommitdiff
path: root/src/mime
diff options
context:
space:
mode:
authorDavid Heuschmann <heuschmann.d@gmail.com>2018-11-20 11:11:59 +0100
committerIan Lance Taylor <iant@golang.org>2018-11-20 14:39:44 +0000
commit2cc6d62d666f49d91c6d088bcba3ef18072d093f (patch)
tree61e61418e587b044991a8965c99231a57101c6d2 /src/mime
parent399fec28e22ac01b7a4fe56028c3016a0df6d2e6 (diff)
downloadgo-2cc6d62d666f49d91c6d088bcba3ef18072d093f.tar.gz
go-2cc6d62d666f49d91c6d088bcba3ef18072d093f.zip
mime: correctly detect non-ASCII characters in FormatMediaType
FormatMediaType used rune&0x80==0 to check if parameter values consisted of valid ascii charaters. Comparing strings using their runes instead of their bytes leads to some non-ascii strings to pass as valid. E.g. the rune for 'Ą' is 0x104, 0x104 & 0x80 => 0. Its byte representation is 0xc4 0x84, both of which result in non zero values when masked with 0x80 Fixes #28849 Change-Id: Ib9fb4968bcbbec0197d81136f380d40a2a56c14b Reviewed-on: https://go-review.googlesource.com/c/150417 Run-TryBot: Ian Lance Taylor <iant@golang.org> TryBot-Result: Gobot Gobot <gobot@golang.org> Reviewed-by: Ian Lance Taylor <iant@golang.org>
Diffstat (limited to 'src/mime')
-rw-r--r--src/mime/mediatype.go2
-rw-r--r--src/mime/mediatype_test.go2
2 files changed, 3 insertions, 1 deletions
diff --git a/src/mime/mediatype.go b/src/mime/mediatype.go
index 3d480a9d7e..fc6e0d0673 100644
--- a/src/mime/mediatype.go
+++ b/src/mime/mediatype.go
@@ -56,7 +56,7 @@ func FormatMediaType(t string, param map[string]string) string {
b.WriteByte('"')
offset := 0
- for index, character := range value {
+ for index, character := range []byte(value) {
if character == '"' || character == '\\' {
b.WriteString(value[offset:index])
offset = index
diff --git a/src/mime/mediatype_test.go b/src/mime/mediatype_test.go
index 35b311a4a5..945a8189e1 100644
--- a/src/mime/mediatype_test.go
+++ b/src/mime/mediatype_test.go
@@ -481,6 +481,8 @@ var formatTests = []formatTest{
{"noslash", map[string]string{"X": "Y"}, "noslash; x=Y"}, // e.g. Content-Disposition values (RFC 2183); issue 11289
{"foo bar/baz", nil, ""},
{"foo/bar baz", nil, ""},
+ {"attachment", map[string]string{"filename": "ĄĄŽŽČČŠŠ"}, ""},
+ {"attachment", map[string]string{"filename": "ÁÁÊÊÇÇÎÎ"}, ""},
{"foo/BAR", nil, "foo/bar"},
{"foo/BAR", map[string]string{"X": "Y"}, "foo/bar; x=Y"},
{"foo/BAR", map[string]string{"space": "With space"}, `foo/bar; space="With space"`},