Bug 699347 - Avoid crashing when viewing source of XML files that have an XML declaration without the encoding pseudo-attribute. r=smaug.
This commit is contained in:
@@ -406,15 +406,24 @@ nsHtml5StreamParser::SniffBOMlessUTF16BasicLatin(const PRUint8* aFromSegment,
|
||||
}
|
||||
|
||||
void
|
||||
nsHtml5StreamParser::MaybeSetEncodingFromExpat(const PRUnichar* aEncoding)
|
||||
nsHtml5StreamParser::SetEncodingFromExpat(const PRUnichar* aEncoding)
|
||||
{
|
||||
nsDependentString utf16(aEncoding);
|
||||
nsCAutoString utf8;
|
||||
CopyUTF16toUTF8(utf16, utf8);
|
||||
if (PreferredForInternalEncodingDecl(utf8)) {
|
||||
mCharset.Assign(utf8);
|
||||
mCharsetSource = kCharsetFromMetaTag; // closest for XML
|
||||
if (aEncoding) {
|
||||
nsDependentString utf16(aEncoding);
|
||||
nsCAutoString utf8;
|
||||
CopyUTF16toUTF8(utf16, utf8);
|
||||
if (PreferredForInternalEncodingDecl(utf8)) {
|
||||
mCharset.Assign(utf8);
|
||||
mCharsetSource = kCharsetFromMetaTag; // closest for XML
|
||||
return;
|
||||
}
|
||||
// else the page declared an encoding Gecko doesn't support and we'd
|
||||
// end up defaulting to UTF-8 anyway. Might as well fall through here
|
||||
// right away and let the encoding be set to UTF-8 which we'd default to
|
||||
// anyway.
|
||||
}
|
||||
mCharset.AssignLiteral("UTF-8"); // XML defaults to UTF-8 without a BOM
|
||||
mCharsetSource = kCharsetFromMetaTag; // means confident
|
||||
}
|
||||
|
||||
// A separate user data struct is used instead of passing the
|
||||
@@ -436,7 +445,7 @@ HandleXMLDeclaration(void* aUserData,
|
||||
int aStandalone)
|
||||
{
|
||||
UserData* ud = static_cast<UserData*>(aUserData);
|
||||
ud->mStreamParser->MaybeSetEncodingFromExpat(
|
||||
ud->mStreamParser->SetEncodingFromExpat(
|
||||
reinterpret_cast<const PRUnichar*>(aEncoding));
|
||||
XML_StopParser(ud->mExpat, false);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user