Commit ef258612 authored by Brad Fitzpatrick's avatar Brad Fitzpatrick

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
parent 9665ce19
......@@ -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) {
......
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