зеркало из https://github.com/mozilla/pjs.git
#88363 Site with duplicate Content-Type loads with incorrect encoding
r=yokoyama sr=waterson
This commit is contained in:
Родитель
6afb953716
Коммит
dde83fbf7b
|
@ -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));
|
||||
}
|
||||
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(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);
|
||||
characterSet = NS_ConvertASCIItoUCS2(charsetheader);
|
||||
nsCOMPtr<nsICharsetAlias> calias(do_GetService(kCharsetAliasCID,&rv));
|
||||
|
||||
if(NS_SUCCEEDED(rv) && calias) {
|
||||
|
|
|
@ -459,51 +459,16 @@ 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);
|
||||
|
||||
nsCOMPtr<nsICharsetAlias> calias(do_CreateInstance(kCharsetAliasCID, &rv));
|
||||
if(calias) {
|
||||
nsAutoString theCharset;
|
||||
contentType.Mid(theCharset, start, end - start);
|
||||
|
||||
nsAutoString preferred;
|
||||
rv = calias->GetPreferred(theCharset, 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);
|
||||
printf("From HTTP Header, charset = %s\n", NS_ConvertUCS2toUTF8(charset).get());
|
||||
#endif
|
||||
charset = preferred;
|
||||
charsetSource = kCharsetFromHTTPHeader;
|
||||
|
@ -511,7 +476,6 @@ nsHTMLDocument::StartDocumentLoad(const char* aCommand,
|
|||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
nsCOMPtr<nsICachingChannel> cachingChan = do_QueryInterface(httpChannel);
|
||||
if (cachingChan) {
|
||||
|
|
|
@ -401,47 +401,21 @@ 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) )
|
||||
{
|
||||
nsCOMPtr<nsICharsetAlias> calias(do_GetService(kCharsetAliasCID,&rv));
|
||||
|
||||
if(NS_SUCCEEDED(rv) && (nsnull != calias) ) {
|
||||
nsAutoString preferred;
|
||||
rv = calias->GetPreferred(theCharset, preferred);
|
||||
if(NS_SUCCEEDED(rv))
|
||||
{
|
||||
rv = calias->GetPreferred(NS_ConvertASCIItoUCS2(charsetheader), preferred);
|
||||
if(NS_SUCCEEDED(rv)){
|
||||
charset = preferred;
|
||||
charsetSource = kCharsetFromHTTPHeader;
|
||||
}
|
||||
nsServiceManager::ReleaseService(kCharsetAliasCID, calias);
|
||||
}
|
||||
}
|
||||
}
|
||||
} //end of checking http channel
|
||||
|
||||
static NS_DEFINE_CID(kCParserCID, NS_PARSER_CID);
|
||||
|
|
|
@ -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,38 +350,19 @@ 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);
|
||||
rv = calias->GetPreferred(NS_ConvertASCIItoUCS2(charsetheader), preferred);
|
||||
if(NS_SUCCEEDED(rv)) {
|
||||
aCharset.Assign(preferred);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return rv;
|
||||
}
|
||||
|
||||
|
|
Загрузка…
Ссылка в новой задаче