1
0
mirror of https://github.com/golang/go synced 2024-11-22 02:54:39 -07:00

mime: fix build

The fix is to add ' ' after ';' so that we match
what we used to generate.
Packages like http look for the string with
the space in it, and I don't see a reason to
be so terse.

Also s/buffer/b/

TBR=bradfitz
CC=golang-dev
https://golang.org/cl/4959044
This commit is contained in:
Russ Cox 2011-08-26 17:19:52 -04:00
parent 75199664d9
commit 91643acc6f
3 changed files with 21 additions and 20 deletions

View File

@ -21,39 +21,40 @@ func FormatMediaType(t, sub string, param map[string]string) string {
if !(IsToken(t) && IsToken(sub)) { if !(IsToken(t) && IsToken(sub)) {
return "" return ""
} }
var buffer bytes.Buffer var b bytes.Buffer
buffer.WriteString(strings.ToLower(t)) b.WriteString(strings.ToLower(t))
buffer.WriteByte('/') b.WriteByte('/')
buffer.WriteString(strings.ToLower(sub)) b.WriteString(strings.ToLower(sub))
for attribute, value := range param { for attribute, value := range param {
buffer.WriteByte(';') b.WriteByte(';')
b.WriteByte(' ')
if !IsToken(attribute) { if !IsToken(attribute) {
return "" return ""
} }
buffer.WriteString(strings.ToLower(attribute)) b.WriteString(strings.ToLower(attribute))
buffer.WriteByte('=') b.WriteByte('=')
if IsToken(value) { if IsToken(value) {
buffer.WriteString(value) b.WriteString(value)
continue continue
} }
buffer.WriteByte('"') b.WriteByte('"')
offset := 0 offset := 0
for index, character := range value { for index, character := range value {
if character == '"' || character == '\r' { if character == '"' || character == '\r' {
buffer.WriteString(value[offset:index]) b.WriteString(value[offset:index])
offset = index offset = index
buffer.WriteByte('\\') b.WriteByte('\\')
} }
if character&0x80 != 0 { if character&0x80 != 0 {
return "" return ""
} }
} }
buffer.WriteString(value[offset:]) b.WriteString(value[offset:])
buffer.WriteByte('"') b.WriteByte('"')
} }
return buffer.String() return b.String()
} }
func checkMediaTypeDisposition(s string) os.Error { func checkMediaTypeDisposition(s string) os.Error {

View File

@ -20,15 +20,15 @@ var typeFiles = []string{
} }
var mimeTypes = map[string]string{ var mimeTypes = map[string]string{
".css": "text/css;charset=utf-8", ".css": "text/css; charset=utf-8",
".gif": "image/gif", ".gif": "image/gif",
".htm": "text/html;charset=utf-8", ".htm": "text/html; charset=utf-8",
".html": "text/html;charset=utf-8", ".html": "text/html; charset=utf-8",
".jpg": "image/jpeg", ".jpg": "image/jpeg",
".js": "application/x-javascript", ".js": "application/x-javascript",
".pdf": "application/pdf", ".pdf": "application/pdf",
".png": "image/png", ".png": "image/png",
".xml": "text/xml;charset=utf-8", ".xml": "text/xml; charset=utf-8",
} }
var mimeLock sync.RWMutex var mimeLock sync.RWMutex

View File

@ -8,7 +8,7 @@ import "testing"
var typeTests = map[string]string{ var typeTests = map[string]string{
".t1": "application/test", ".t1": "application/test",
".t2": "text/test;charset=utf-8", ".t2": "text/test; charset=utf-8",
".png": "image/png", ".png": "image/png",
} }
@ -25,7 +25,7 @@ func TestTypeByExtension(t *testing.T) {
} }
func TestCustomExtension(t *testing.T) { func TestCustomExtension(t *testing.T) {
custom := "text/xml;charset=iso-8859-1" custom := "text/xml; charset=iso-8859-1"
if error := AddExtensionType(".xml", custom); error != nil { if error := AddExtensionType(".xml", custom); error != nil {
t.Fatalf("error %s for AddExtension(%s)", error, custom) t.Fatalf("error %s for AddExtension(%s)", error, custom)
} }