From b1eec4ec0700961654381d6d1784134e8f5a25d4 Mon Sep 17 00:00:00 2001 From: "loadrunner%betak.net" Date: Fri, 10 Aug 2001 02:15:41 +0000 Subject: [PATCH] bug 91696, Meta tag does not work, r=shanjian , sr=vidur --- htmlparser/src/nsParser.cpp | 2 +- intl/chardet/src/nsMetaCharsetObserver.cpp | 41 +++++++++++++++------- parser/htmlparser/src/nsParser.cpp | 2 +- 3 files changed, 31 insertions(+), 14 deletions(-) diff --git a/htmlparser/src/nsParser.cpp b/htmlparser/src/nsParser.cpp index c7f9548d939..c03cab181b1 100644 --- a/htmlparser/src/nsParser.cpp +++ b/htmlparser/src/nsParser.cpp @@ -2520,7 +2520,7 @@ nsParser::DetectMetaTag(const char* aBytes, if ((offset = tokenizer.GetNextWord(PR_TRUE)) != kNotFound) { const char* contentStart = attrStart+offset; CWordTokenizer contentTokenizer(contentStart, 0, - tokenizer.GetLength()); + attrEnd-contentStart); // Read the content type if (contentTokenizer.GetNextWord() != kNotFound) { diff --git a/intl/chardet/src/nsMetaCharsetObserver.cpp b/intl/chardet/src/nsMetaCharsetObserver.cpp index 06819322ee1..8a713ba4699 100644 --- a/intl/chardet/src/nsMetaCharsetObserver.cpp +++ b/intl/chardet/src/nsMetaCharsetObserver.cpp @@ -179,12 +179,16 @@ NS_IMETHODIMP nsMetaCharsetObserver::Notify( PRInt32 i; const PRUnichar *httpEquivValue=nsnull; const PRUnichar *contentValue=nsnull; + const PRUnichar *charsetValue=nsnull; + for(i=0;i<(numOfAttributes-3);i++) { if(0 == nsCRT::strcasecmp((keys->StringAt(i))->get(), "HTTP-EQUIV")) httpEquivValue=((values->StringAt(i))->get()); else if(0 == nsCRT::strcasecmp((keys->StringAt(i))->get(), "content")) contentValue=(values->StringAt(i))->get(); + else if(0 == nsCRT::strcasecmp((keys->StringAt(i))->get(), "charset")) + charsetValue=(values->StringAt(i))->get(); } NS_NAMED_LITERAL_STRING(contenttype, "Content-Type"); NS_NAMED_LITERAL_STRING(texthtml, "text/html"); @@ -213,18 +217,31 @@ NS_IMETHODIMP nsMetaCharsetObserver::Notify( )) ) { - nsAutoString contentPart1(contentValue+10); // after "text/html;" - PRInt32 start = contentPart1.RFind("charset=", PR_TRUE ) ; - if(kNotFound != start) - { - start += 8; // 8 = "charset=".length - PRInt32 end = contentPart1.FindCharInSet("\'\";", start ); - if(kNotFound == end ) - end = contentPart1.Length(); - nsAutoString newCharset; - NS_ASSERTION(end>=start, "wrong index"); - contentPart1.Mid(newCharset, start, end - start); + + nsAutoString newCharset; + + if (nsnull == charsetValue) + { + nsAutoString contentPart1(contentValue+10); // after "text/html;" + PRInt32 start = contentPart1.RFind("charset=", PR_TRUE ) ; + if(kNotFound != start) + { + start += 8; // 8 = "charset=".length + PRInt32 end = contentPart1.FindCharInSet("\'\";", start ); + if(kNotFound == end ) + end = contentPart1.Length(); + NS_ASSERTION(end>=start, "wrong index"); + contentPart1.Mid(newCharset, start, end - start); + } + } + else + { + newCharset = charsetValue; + } + + if (!newCharset.IsEmpty()) + { nsAutoString charsetString(charset); if(! newCharset.EqualsIgnoreCase(charsetString)) { @@ -248,7 +265,7 @@ NS_IMETHODIMP nsMetaCharsetObserver::Notify( } // if(NS_SUCCEEDED(res) } } // if EqualIgnoreCase - } // if (kNotFound != start) + } // if !newCharset.IsEmpty() } // if } else diff --git a/parser/htmlparser/src/nsParser.cpp b/parser/htmlparser/src/nsParser.cpp index c7f9548d939..c03cab181b1 100644 --- a/parser/htmlparser/src/nsParser.cpp +++ b/parser/htmlparser/src/nsParser.cpp @@ -2520,7 +2520,7 @@ nsParser::DetectMetaTag(const char* aBytes, if ((offset = tokenizer.GetNextWord(PR_TRUE)) != kNotFound) { const char* contentStart = attrStart+offset; CWordTokenizer contentTokenizer(contentStart, 0, - tokenizer.GetLength()); + attrEnd-contentStart); // Read the content type if (contentTokenizer.GetNextWord() != kNotFound) {