mirror of https://github.com/golang/go.git
mime: sort attributes in FormatMediaType
Map iteration order issue. Go 1.2 and earlier had stable results for small maps. Fixes #8115 LGTM=r, rsc R=golang-codereviews, r CC=dsymonds, golang-codereviews, iant, rsc https://golang.org/cl/98580047
This commit is contained in:
parent
9665ce19af
commit
ef25861222
|
|
@ -8,6 +8,7 @@ import (
|
|||
"bytes"
|
||||
"errors"
|
||||
"fmt"
|
||||
"sort"
|
||||
"strings"
|
||||
"unicode"
|
||||
)
|
||||
|
|
@ -31,7 +32,14 @@ func FormatMediaType(t string, param map[string]string) string {
|
|||
b.WriteByte('/')
|
||||
b.WriteString(strings.ToLower(sub))
|
||||
|
||||
for attribute, value := range param {
|
||||
attrs := make([]string, 0, len(param))
|
||||
for a := range param {
|
||||
attrs = append(attrs, a)
|
||||
}
|
||||
sort.Strings(attrs)
|
||||
|
||||
for _, attribute := range attrs {
|
||||
value := param[attribute]
|
||||
b.WriteByte(';')
|
||||
b.WriteByte(' ')
|
||||
if !isToken(attribute) {
|
||||
|
|
|
|||
|
|
@ -293,6 +293,7 @@ var formatTests = []formatTest{
|
|||
{"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: ä"}, ""},
|
||||
{"foo/bar", map[string]string{"a": "av", "b": "bv", "c": "cv"}, "foo/bar; a=av; b=bv; c=cv"},
|
||||
}
|
||||
|
||||
func TestFormatMediaType(t *testing.T) {
|
||||
|
|
|
|||
Loading…
Reference in New Issue