mirror of
https://github.com/golang/go
synced 2024-11-23 17:00:07 -07:00
mime: fix parsing of empty string attribute value
Fixes #11290. Change-Id: I312f0731077b78a4bed47062eb7fd1ab52bc3dd1 Reviewed-on: https://go-review.googlesource.com/17453 Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org> Run-TryBot: Brad Fitzpatrick <bradfitz@golang.org> TryBot-Result: Gobot Gobot <gobot@golang.org>
This commit is contained in:
parent
35e84546d7
commit
025e9b0ca3
@ -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) {
|
||||
|
Loading…
Reference in New Issue
Block a user