]> Cypherpunks repositories - gostls13.git/commitdiff
net/http: fix whitespace handling in sniffer.
authorDavid Symonds <dsymonds@golang.org>
Mon, 7 Nov 2011 00:55:33 +0000 (11:55 +1100)
committerDavid Symonds <dsymonds@golang.org>
Mon, 7 Nov 2011 00:55:33 +0000 (11:55 +1100)
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

src/pkg/net/http/sniff.go
src/pkg/net/http/sniff_test.go

index 690b1ac9fb805079a6543bee24fed7306090123f..5707c7f057f2e03152f832dad706e3ec9c0b0b55 100644 (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 {
index faf05e405a57bdfac9d2cb003431bbd3721f24c0..e9195a5e164de8a2fa44f4ccd90f492fadaaced2 100644 (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"},