]> Cypherpunks repositories - gostls13.git/commitdiff
mime: escape backslash in attribute values
authorPieter Droogendijk <pieter@binky.org.uk>
Fri, 9 Aug 2013 20:10:53 +0000 (13:10 -0700)
committerBrad Fitzpatrick <bradfitz@golang.org>
Fri, 9 Aug 2013 20:10:53 +0000 (13:10 -0700)
R=golang-dev, bradfitz
CC=golang-dev
https://golang.org/cl/12689045

src/pkg/mime/mediatype.go
src/pkg/mime/mediatype_test.go

index 8396c0a155b4cb33ba0009c158353936ea75b770..608f759da8f315795310291f25fbc9a92c2c5a29 100644 (file)
@@ -47,7 +47,7 @@ func FormatMediaType(t string, param map[string]string) string {
                b.WriteByte('"')
                offset := 0
                for index, character := range value {
-                       if character == '"' || character == '\r' {
+                       if character == '"' || character == '\\' {
                                b.WriteString(value[offset:index])
                                offset = index
                                b.WriteByte('\\')
index e41ead237a5b508ebb77db51812a42982046c5e5..29511445bcffcdf323c5e3e8d7c40e04f0e27391 100644 (file)
@@ -282,8 +282,17 @@ type formatTest struct {
 
 var formatTests = []formatTest{
        {"noslash", nil, ""},
+       {"foo bar/baz", nil, ""},
+       {"foo/bar baz", nil, ""},
        {"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"`},
+       {"foo/BAR", map[string]string{"quote": `With "quote`}, `foo/bar; quote="With \"quote"`},
+       {"foo/BAR", map[string]string{"bslash": `With \backslash`}, `foo/bar; bslash="With \\backslash"`},
+       {"foo/BAR", map[string]string{"both": `With \backslash and "quote`}, `foo/bar; both="With \\backslash and \"quote"`},
+       {"foo/BAR", map[string]string{"": "empty attribute"}, ""},
+       {"foo/BAR", map[string]string{"bad attribute": "baz"}, ""},
+       {"foo/BAR", map[string]string{"nonascii": "not an ascii character: รค"}, ""},
 }
 
 func TestFormatMediaType(t *testing.T) {