From 205a8aa5f34e9a6db75579721bf27bc6bd64de93 Mon Sep 17 00:00:00 2001 From: "bzbarsky%mit.edu" Date: Tue, 18 Nov 2003 15:10:56 +0000 Subject: [PATCH] Decide it's application/octet-stream if it contains any ASCII control chars, not just if it contains a null byte. Bug 126782, r+sr=darin git-svn-id: svn://10.0.0.236/trunk@149497 18797224-902f-48f8-a5cc-f745e15eee43 --- .../netwerk/streamconv/converters/nsUnknownDecoder.cpp | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/mozilla/netwerk/streamconv/converters/nsUnknownDecoder.cpp b/mozilla/netwerk/streamconv/converters/nsUnknownDecoder.cpp index 037e4cb0246..6a3e9985be4 100644 --- a/mozilla/netwerk/streamconv/converters/nsUnknownDecoder.cpp +++ b/mozilla/netwerk/streamconv/converters/nsUnknownDecoder.cpp @@ -491,16 +491,22 @@ PRBool nsUnknownDecoder::SniffURI(nsIRequest* aRequest) return PR_FALSE; } +// This macro is based on RFC 2046 Section 4.1.2. Treat any char 0-31 +// except the 9-13 range (\t, \n, \v, \f, \r) as non-text +#define IS_TEXT_CHAR(ch) \ + (((unsigned char)(ch)) & 31 != ((unsigned char)(ch)) || \ + (9 <= ch && ch <= 13)) + PRBool nsUnknownDecoder::LastDitchSniff(nsIRequest* aRequest) { // All we can do now is try to guess whether this is text/plain or // application/octet-stream // - // See if the buffer has any embedded nulls. If not, then lets just + // See if the buffer has any non-text chars. If not, then lets just // call it text/plain... // PRUint32 i; - for (i=0; i