Commit b990c40d authored by Pieter Droogendijk's avatar Pieter Droogendijk Committed by Brad Fitzpatrick

mime: escape backslash in attribute values

R=golang-dev, bradfitz
CC=golang-dev
https://golang.org/cl/12689045
parent 2db5e4bb
......@@ -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('\\')
......
......@@ -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) {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment