net/http: fix whitespace handling in sniffer.

A single character typo ("\n" instead of "\r") meant that
HTML data using DOS line breaks (CRLF) was not detected as HTML.

R=golang-dev, adg
CC=golang-dev
https://golang.org/cl/5365041
This commit is contained in:
David Symonds 2011-11-07 11:55:33 +11:00
parent 603d80c28d
commit 75af79b9b5
2 changed files with 2 additions and 1 deletions

View file

@ -38,7 +38,7 @@ func DetectContentType(data []byte) string {
}
func isWS(b byte) bool {
return bytes.IndexByte([]byte("\t\n\x0C\n "), b) != -1
return bytes.IndexByte([]byte("\t\n\x0C\r "), b) != -1
}
type sniffSig interface {

View file

@ -26,6 +26,7 @@ var sniffTests = []struct {
{"HTML document #1", []byte(`<HtMl><bOdY>blah blah blah</body></html>`), "text/html; charset=utf-8"},
{"HTML document #2", []byte(`<HTML></HTML>`), "text/html; charset=utf-8"},
{"HTML document #3 (leading whitespace)", []byte(` <!DOCTYPE HTML>...`), "text/html; charset=utf-8"},
{"HTML document #4 (leading CRLF)", []byte("\r\n<html>..."), "text/html; charset=utf-8"},
{"Plain text", []byte(`This is not HTML. It has ☃ though.`), "text/plain; charset=utf-8"},