Closed
Description
What version of Go are you using (go version
)?
go version go1.8.3 darwin/amd64
What operating system and processor architecture are you using (go env
)?
GOARCH="amd64"
GOBIN=""
GOEXE=""
GOHOSTARCH="amd64"
GOHOSTOS="darwin"
GOOS="darwin"
GOPATH="/Users/alex/Documents/Code/Go"
GORACE=""
GOROOT="/usr/local/Cellar/go/1.8.3/libexec"
GOTOOLDIR="/usr/local/Cellar/go/1.8.3/libexec/pkg/tool/darwin_amd64"
GCCGO="gccgo"
CC="clang"
GOGCCFLAGS="-fPIC -m64 -pthread -fno-caret-diagnostics -Qunused-arguments -fmessage-length=0 -fdebug-prefix-map=/var/folders/23/qy5hclf52mdfnx7xgn1ddk6r0000gn/T/go-build891556908=/tmp/go-build -gno-record-gcc-switches -fno-common"
CXX="clang++"
CGO_ENABLED="1"
PKG_CONFIG="pkg-config"
CGO_CFLAGS="-g -O2"
CGO_CPPFLAGS=""
CGO_CXXFLAGS="-g -O2"
CGO_FFLAGS="-g -O2"
What did you do?
Run this code, which is on the playground:
package main
import (
"fmt"
"net/http"
)
func main() {
document := "<!DOCTYPE html><html></html>"
bom := "\xef\xbb\xbf"
fmt.Println(http.DetectContentType([]byte(document)))
fmt.Println(http.DetectContentType([]byte(bom+document)))
}
What did you expect to see?
text/html; charset=utf-8
text/html; charset=utf-8
What did you see instead?
text/html; charset=utf-8
text/plain; charset=utf-8
It seems from sniff.go that a BOM automatically triggers a text/plain MIME type. Ideally, htmlSig
would detect UTF-8 BOMs and skip past them.