From 75af79b9b59548c3177b7a0307d6ab75fbbd87a2 Mon Sep 17 00:00:00 2001 From: David Symonds Date: Mon, 7 Nov 2011 11:55:33 +1100 Subject: [PATCH] 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 --- src/pkg/net/http/sniff.go | 2 +- src/pkg/net/http/sniff_test.go | 1 + 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/src/pkg/net/http/sniff.go b/src/pkg/net/http/sniff.go index 690b1ac9fb..5707c7f057 100644 --- a/src/pkg/net/http/sniff.go +++ b/src/pkg/net/http/sniff.go @@ -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 { diff --git a/src/pkg/net/http/sniff_test.go b/src/pkg/net/http/sniff_test.go index faf05e405a..e9195a5e16 100644 --- a/src/pkg/net/http/sniff_test.go +++ b/src/pkg/net/http/sniff_test.go @@ -26,6 +26,7 @@ var sniffTests = []struct { {"HTML document #1", []byte(`blah blah blah`), "text/html; charset=utf-8"}, {"HTML document #2", []byte(``), "text/html; charset=utf-8"}, {"HTML document #3 (leading whitespace)", []byte(` ...`), "text/html; charset=utf-8"}, + {"HTML document #4 (leading CRLF)", []byte("\r\n..."), "text/html; charset=utf-8"}, {"Plain text", []byte(`This is not HTML. It has ☃ though.`), "text/plain; charset=utf-8"},