mirror of
https://github.com/mozilla/gecko-dev.git
synced 2025-02-17 22:32:51 +00:00
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:
parent
9e722c9ee8
commit
a4642bfe44
@ -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);
|
||||
}
|
||||
|
@ -210,9 +210,10 @@ class nsHtml5StreamParser : public nsIStreamListener,
|
||||
|
||||
/**
|
||||
* Sets mCharset and mCharsetSource appropriately for the XML View Source
|
||||
* case if aEncoding names a supported rough ASCII superset.
|
||||
* case if aEncoding names a supported rough ASCII superset and sets
|
||||
* the mCharset and mCharsetSource to the UTF-8 default otherwise.
|
||||
*/
|
||||
void MaybeSetEncodingFromExpat(const PRUnichar* aEncoding);
|
||||
void SetEncodingFromExpat(const PRUnichar* aEncoding);
|
||||
|
||||
private:
|
||||
|
||||
|
1
parser/htmlparser/tests/crashtests/699347-1.xml
Normal file
1
parser/htmlparser/tests/crashtests/699347-1.xml
Normal file
@ -0,0 +1 @@
|
||||
<?xml version="1.0"?><root/>
|
@ -48,3 +48,4 @@ load 574884-2.html
|
||||
load 591330-1.html
|
||||
load 650501-1.xhtml
|
||||
load 696651-1.html
|
||||
load view-source:699347-1.xml
|
||||
|
Loading…
x
Reference in New Issue
Block a user