Backed out changeset dc6b9ca8f3fa (bug 1727491) for causing mochitest failures on test_bug631751be.html. CLOSED TREE
This commit is contained in:
@@ -503,6 +503,44 @@ void nsHtml5StreamParser::SetupDecodingFromUtf16BogoXml(
|
||||
mLastBuffer->AdvanceEnd(3);
|
||||
}
|
||||
|
||||
void nsHtml5StreamParser::SniffBOMlessUTF16BasicLatin(const uint8_t* aBuf,
|
||||
size_t aBufLen) {
|
||||
// Avoid underspecified heuristic craziness for XHR
|
||||
if (mMode == LOAD_AS_DATA) {
|
||||
return;
|
||||
}
|
||||
// Make sure there's enough data. Require room for "<title></title>"
|
||||
if (aBufLen < 30) {
|
||||
return;
|
||||
}
|
||||
// even-numbered bytes tracked at 0, odd-numbered bytes tracked at 1
|
||||
bool byteZero[2] = {false, false};
|
||||
bool byteNonZero[2] = {false, false};
|
||||
uint32_t i = 0;
|
||||
for (; i < aBufLen; ++i) {
|
||||
if (aBuf[i]) {
|
||||
if (byteNonZero[1 - (i % 2)]) {
|
||||
return;
|
||||
}
|
||||
byteNonZero[i % 2] = true;
|
||||
} else {
|
||||
if (byteZero[1 - (i % 2)]) {
|
||||
return;
|
||||
}
|
||||
byteZero[i % 2] = true;
|
||||
}
|
||||
}
|
||||
if (byteNonZero[0]) {
|
||||
mEncoding = UTF_16LE_ENCODING;
|
||||
} else {
|
||||
mEncoding = UTF_16BE_ENCODING;
|
||||
}
|
||||
mCharsetSource = kCharsetFromIrreversibleAutoDetection;
|
||||
mTreeBuilder->SetDocumentCharset(mEncoding, mCharsetSource);
|
||||
DontGuessEncoding();
|
||||
mTreeBuilder->MaybeComplainAboutCharset("EncBomlessUtf16", true, 0);
|
||||
}
|
||||
|
||||
void nsHtml5StreamParser::SetEncodingFromExpat(const char16_t* aEncoding) {
|
||||
if (aEncoding) {
|
||||
nsDependentString utf16(aEncoding);
|
||||
@@ -696,9 +734,15 @@ nsresult nsHtml5StreamParser::FinalizeSniffing(Span<const uint8_t> aFromSegment,
|
||||
mEncoding = WrapNotNull(encoding);
|
||||
mCharsetSource = kCharsetFromXmlDeclaration;
|
||||
mTreeBuilder->SetDocumentCharset(mEncoding, mCharsetSource);
|
||||
} else if (mCharsetSource < kCharsetFromIrreversibleAutoDetection) {
|
||||
// meta scan and XML declaration check failed.
|
||||
// Check for BOMless UTF-16 with Basic
|
||||
// Latin content for compat with IE. See bug 631751.
|
||||
SniffBOMlessUTF16BasicLatin(buf, bufLen);
|
||||
}
|
||||
}
|
||||
if (mForceAutoDetection) {
|
||||
if (mForceAutoDetection &&
|
||||
mCharsetSource != kCharsetFromIrreversibleAutoDetection) {
|
||||
// neither meta nor XML declaration found, honor override
|
||||
FinalizeSniffingWithDetector(aFromSegment, aCountToSniffingLimit, false);
|
||||
return SetupDecodingAndWriteSniffingBufferAndCurrentSegment(aFromSegment);
|
||||
@@ -893,10 +937,11 @@ nsresult nsHtml5StreamParser::SniffStreamBytes(
|
||||
return SetupDecodingAndWriteSniffingBufferAndCurrentSegment(aFromSegment);
|
||||
}
|
||||
|
||||
MOZ_ASSERT(!(mBomState == BOM_SNIFFING_OVER && mChannelHadCharset &&
|
||||
!mForceAutoDetection),
|
||||
"How come we're running post-BOM sniffing with channel charset unless "
|
||||
"we're also processing forced detection?");
|
||||
MOZ_ASSERT(
|
||||
!(mBomState == BOM_SNIFFING_OVER && mChannelHadCharset &&
|
||||
!mForceAutoDetection),
|
||||
"How come we're running post-BOM sniffing with channel charset unless "
|
||||
"we're also processing forced detection?");
|
||||
|
||||
if (!mMetaScanner &&
|
||||
(mMode == NORMAL || mMode == VIEW_SOURCE_HTML || mMode == LOAD_AS_DATA)) {
|
||||
|
||||
Reference in New Issue
Block a user