mirror of
https://github.com/mozilla/gecko-dev.git
synced 2024-10-09 03:15:11 +00:00
Bug 863025 - Fix nsUniversalDetector overlooking the UTF-16 BOM. r=smontagu
This commit is contained in:
parent
72635c5a76
commit
67d9eda26a
@ -77,31 +77,34 @@ nsresult nsUniversalDetector::HandleData(const char* aBuf, uint32_t aLen)
|
||||
if (mStart)
|
||||
{
|
||||
mStart = false;
|
||||
if (aLen > 2)
|
||||
switch (aBuf[0])
|
||||
{
|
||||
case '\xEF':
|
||||
if (('\xBB' == aBuf[1]) && ('\xBF' == aBuf[2]))
|
||||
// EF BB BF UTF-8 encoded BOM
|
||||
mDetectedCharset = "UTF-8";
|
||||
if (aLen >= 2) {
|
||||
switch (aBuf[0]) {
|
||||
case '\xEF':
|
||||
if ((aLen > 2) && ('\xBB' == aBuf[1]) && ('\xBF' == aBuf[2])) {
|
||||
// EF BB BF UTF-8 encoded BOM
|
||||
mDetectedCharset = "UTF-8";
|
||||
}
|
||||
break;
|
||||
case '\xFE':
|
||||
if ('\xFF' == aBuf[1])
|
||||
// FE FF UTF-16, big endian BOM
|
||||
mDetectedCharset = "UTF-16BE";
|
||||
case '\xFE':
|
||||
if ('\xFF' == aBuf[1]) {
|
||||
// FE FF UTF-16, big endian BOM
|
||||
mDetectedCharset = "UTF-16BE";
|
||||
}
|
||||
break;
|
||||
case '\xFF':
|
||||
if ('\xFE' == aBuf[1])
|
||||
// FF FE UTF-16, little endian BOM
|
||||
mDetectedCharset = "UTF-16LE";
|
||||
case '\xFF':
|
||||
if ('\xFE' == aBuf[1]) {
|
||||
// FF FE UTF-16, little endian BOM
|
||||
mDetectedCharset = "UTF-16LE";
|
||||
}
|
||||
break;
|
||||
} // switch
|
||||
}
|
||||
|
||||
if (mDetectedCharset)
|
||||
{
|
||||
mDone = true;
|
||||
return NS_OK;
|
||||
}
|
||||
if (mDetectedCharset)
|
||||
{
|
||||
mDone = true;
|
||||
return NS_OK;
|
||||
}
|
||||
}
|
||||
|
||||
uint32_t i;
|
||||
|
Loading…
Reference in New Issue
Block a user