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
This commit is contained in:
bzbarsky%mit.edu 2003-11-18 15:10:56 +00:00
parent f55828685b
commit 205a8aa5f3

View File

@ -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<mBufferLen && mBuffer[i]; i++);
for (i=0; i<mBufferLen && IS_TEXT_CHAR(mBuffer[i]); i++);
if (i == mBufferLen) {
mContentType = TEXT_PLAIN;