Commit 025e9b0c authored by Russ Cox's avatar Russ Cox Committed by Brad Fitzpatrick

mime: fix parsing of empty string attribute value

Fixes #11290.

Change-Id: I312f0731077b78a4bed47062eb7fd1ab52bc3dd1
Reviewed-on: https://go-review.googlesource.com/17453Reviewed-by: 's avatarBrad Fitzpatrick <bradfitz@golang.org>
Run-TryBot: Brad Fitzpatrick <bradfitz@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
parent 35e84546
......@@ -289,10 +289,11 @@ func consumeMediaParam(v string) (param, value, rest string) {
}
rest = rest[1:] // consume equals sign
rest = strings.TrimLeftFunc(rest, unicode.IsSpace)
value, rest = consumeValue(rest)
if value == "" {
value, rest2 := consumeValue(rest)
if value == "" && rest2 == rest {
return "", "", v
}
rest = rest2
return param, value, rest
}
......
......@@ -217,6 +217,9 @@ func TestParseMediaType(t *testing.T) {
{`form-data; firstname="Брэд"; lastname="Фицпатрик"`,
"form-data",
m("firstname", "Брэд", "lastname", "Фицпатрик")},
// Empty string used to be mishandled.
{`foo; bar=""`, "foo", m("bar", "")},
}
for _, test := range tests {
mt, params, err := ParseMediaType(test.in)
......@@ -295,6 +298,7 @@ var formatTests = []formatTest{
{"foo/BAR", map[string]string{"nonascii": "not an ascii character: ä"}, ""},
{"foo/bar", map[string]string{"a": "av", "b": "bv", "c": "cv"}, "foo/bar; a=av; b=bv; c=cv"},
{"foo/bar", map[string]string{"0": "'", "9": "'"}, "foo/bar; 0='; 9='"},
{"foo", map[string]string{"bar": ""}, `foo; bar=""`},
}
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