#88363 Site with duplicate Content-Type loads with incorrect encoding

r=yokoyama sr=waterson
This commit is contained in:
shanjian%netscape.com 2001-10-10 23:37:18 +00:00
Родитель 6afb953716
Коммит dde83fbf7b
4 изменённых файлов: 52 добавлений и 130 удалений

Просмотреть файл

@ -626,7 +626,6 @@ nsScriptLoader::OnStreamComplete(nsIStreamLoader* aLoader,
if (stringLen) {
nsAutoString characterSet, preferred;
nsCOMPtr<nsIUnicodeDecoder> unicodeDecoder;
nsXPIDLCString contenttypeheader;
nsCOMPtr<nsIHttpChannel> httpChannel;
nsCOMPtr<nsIChannel> channel;
@ -639,22 +638,11 @@ nsScriptLoader::OnStreamComplete(nsIStreamLoader* aLoader,
httpChannel = do_QueryInterface(channel);
if (httpChannel) {
rv = httpChannel->GetResponseHeader("content-type",
getter_Copies(contenttypeheader));
}
if (NS_SUCCEEDED(rv)) {
nsAutoString contentType;
contentType.AssignWithConversion(contenttypeheader.get());
PRInt32 start = contentType.RFind("charset=", PR_TRUE ) ;
if(kNotFound != start) {
start += 8; // 8 = "charset=".length
PRInt32 end = contentType.FindCharInSet(";\n\r ", start );
if(kNotFound == end ) end = contentType.Length();
contentType.Mid(characterSet, start, end - start);
nsXPIDLCString charsetheader;
rv = httpChannel->GetCharset(getter_Copies(charsetheader));
if (NS_SUCCEEDED(rv)) {
characterSet = NS_ConvertASCIItoUCS2(charsetheader);
nsCOMPtr<nsICharsetAlias> calias(do_GetService(kCharsetAliasCID,&rv));
if(NS_SUCCEEDED(rv) && calias) {

Просмотреть файл

@ -459,59 +459,23 @@ nsHTMLDocument::StartDocumentLoad(const char* aCommand,
}
if(kCharsetFromHTTPHeader > charsetSource) {
nsXPIDLCString contenttypeheader;
rv = httpChannel->GetResponseHeader("content-type",
getter_Copies(contenttypeheader));
nsXPIDLCString charsetheader;
rv = httpChannel->GetCharset(getter_Copies(charsetheader));
if (NS_SUCCEEDED(rv)) {
nsAutoString contentType;
contentType.AssignWithConversion(NS_STATIC_CAST(const char*,
contenttypeheader));
PRInt32 start = contentType.RFind("charset=", PR_TRUE ) ;
if(start != kNotFound) {
start += 8; // 8 = "charset=".length
PRInt32 end = 0;
if (contentType.Length() >= (PRUint32)start &&
contentType.CharAt(start) == PRUnichar('"')) {
start++;
end = contentType.FindCharInSet("\"", start);
if (kNotFound == end) {
end = contentType.Length();
}
} else {
end = contentType.FindCharInSet(";\n\r ", start);
if(kNotFound == end) {
end = contentType.Length();
}
}
nsCOMPtr<nsICharsetAlias> calias =
do_CreateInstance(kCharsetAliasCID);
if (calias) {
nsAutoString theCharset;
contentType.Mid(theCharset, start, end - start);
nsAutoString preferred;
rv = calias->GetPreferred(theCharset, preferred);
if (NS_SUCCEEDED(rv)) {
nsCOMPtr<nsICharsetAlias> calias(do_CreateInstance(kCharsetAliasCID, &rv));
if(calias) {
nsAutoString preferred;
rv = calias->GetPreferred(NS_ConvertASCIItoUCS2(charsetheader), preferred);
if(NS_SUCCEEDED(rv)) {
#ifdef DEBUG_charset
char* cCharset = ToNewCString(charset);
printf("From HTTP Header, charset = %s\n", cCharset);
Recycle(cCharset);
#endif
charset = preferred;
charsetSource = kCharsetFromHTTPHeader;
}
printf("From HTTP Header, charset = %s\n", NS_ConvertUCS2toUTF8(charset).get());
#endif
charset = preferred;
charsetSource = kCharsetFromHTTPHeader;
}
}
}
}
}
}
nsCOMPtr<nsICachingChannel> cachingChan = do_QueryInterface(httpChannel);
if (cachingChan) {

Просмотреть файл

@ -401,45 +401,19 @@ nsXMLDocument::StartDocumentLoad(const char* aCommand,
nsCOMPtr<nsIHttpChannel> httpChannel = do_QueryInterface(aChannel);
if(httpChannel) {
nsXPIDLCString contenttypeheader;
rv = httpChannel->GetResponseHeader("content-type", getter_Copies(contenttypeheader));
nsXPIDLCString charsetheader;
rv = httpChannel->GetCharset(getter_Copies(charsetheader));
if (NS_SUCCEEDED(rv)) {
nsAutoString contentType;
contentType.AssignWithConversion( NS_STATIC_CAST(const char*, contenttypeheader) );
PRInt32 start = contentType.RFind("charset=", PR_TRUE ) ;
if(kNotFound != start)
{
start += 8; // 8 = "charset=".length
PRInt32 end = 0;
if(PRUnichar('"') == contentType.CharAt(start)) {
start++;
end = contentType.FindCharInSet("\"", start );
if(kNotFound == end )
end = contentType.Length();
} else {
end = contentType.FindCharInSet(";\n\r ", start );
if(kNotFound == end )
end = contentType.Length();
}
nsAutoString theCharset;
contentType.Mid(theCharset, start, end - start);
nsICharsetAlias* calias = nsnull;
rv = nsServiceManager::GetService(
kCharsetAliasCID,
NS_GET_IID(nsICharsetAlias),
(nsISupports**) &calias);
if(NS_SUCCEEDED(rv) && (nsnull != calias) )
{
nsAutoString preferred;
rv = calias->GetPreferred(theCharset, preferred);
if(NS_SUCCEEDED(rv))
{
charset = preferred;
charsetSource = kCharsetFromHTTPHeader;
}
nsServiceManager::ReleaseService(kCharsetAliasCID, calias);
nsCOMPtr<nsICharsetAlias> calias(do_GetService(kCharsetAliasCID,&rv));
if(NS_SUCCEEDED(rv) && (nsnull != calias) ) {
nsAutoString preferred;
rv = calias->GetPreferred(NS_ConvertASCIItoUCS2(charsetheader), preferred);
if(NS_SUCCEEDED(rv)){
charset = preferred;
charsetSource = kCharsetFromHTTPHeader;
}
nsServiceManager::ReleaseService(kCharsetAliasCID, calias);
}
}
} //end of checking http channel

Просмотреть файл

@ -2,16 +2,31 @@
/* ***** BEGIN LICENSE BLOCK *****
* Version: NPL 1.1/GPL 2.0/LGPL 2.1
*
<<<<<<< nsXMLHttpRequest.cpp
* The contents of this file are subject to the Netscape Public
* License Version 1.1 (the "License"); you may not use this file
* except in compliance with the License. You may obtain a copy of
* the License at http://www.mozilla.org/NPL/
=======
* The contents of this file are subject to the Netscape Public License
* Version 1.1 (the "License"); you may not use this file except in
* compliance with the License. You may obtain a copy of the License at
* http://www.mozilla.org/NPL/
>>>>>>> 1.43
*
<<<<<<< nsXMLHttpRequest.cpp
* Software distributed under the License is distributed on an "AS
* IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
* implied. See the License for the specific language governing
* rights and limitations under the License.
*
=======
* Software distributed under the License is distributed on an "AS IS" basis,
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
* for the specific language governing rights and limitations under the
* License.
*
>>>>>>> 1.43
* The Original Code is mozilla.org code.
*
* The Initial Developer of the Original Code is
@ -335,34 +350,15 @@ nsXMLHttpRequest::DetectCharset(nsAWritableString& aCharset)
nsresult rv;
nsCOMPtr<nsIHttpChannel> httpChannel(do_QueryInterface(mChannel,&rv));
if(httpChannel) {
nsXPIDLCString contenttypeheader;
rv = httpChannel->GetResponseHeader("content-type", getter_Copies(contenttypeheader));
nsXPIDLCString charsetheader;
rv = httpChannel->GetCharset(getter_Copies(charsetheader));
if (NS_SUCCEEDED(rv)) {
nsAutoString contentType;
contentType.AssignWithConversion( contenttypeheader.get() );
PRInt32 start = contentType.RFind("charset=", PR_TRUE ) ;
if(start>=0) {
start += 8; // 8 = "charset=".length
PRInt32 end = 0;
if(PRUnichar('"') == contentType.CharAt(start)) {
start++;
end = contentType.FindCharInSet("\"", start );
if(end<0)
end = contentType.Length();
} else {
end = contentType.FindCharInSet(";\n\r ", start );
if(end<0)
end = contentType.Length();
}
nsAutoString theCharset;
contentType.Mid(theCharset, start, end - start);
nsCOMPtr<nsICharsetAlias> calias(do_GetService(kCharsetAliasCID,&rv));
if(NS_SUCCEEDED(rv) && calias) {
nsAutoString preferred;
rv = calias->GetPreferred(theCharset, preferred);
if(NS_SUCCEEDED(rv)) {
aCharset.Assign(preferred);
}
nsCOMPtr<nsICharsetAlias> calias(do_GetService(kCharsetAliasCID,&rv));
if(NS_SUCCEEDED(rv) && calias) {
nsAutoString preferred;
rv = calias->GetPreferred(NS_ConvertASCIItoUCS2(charsetheader), preferred);
if(NS_SUCCEEDED(rv)) {
aCharset.Assign(preferred);
}
}
}