Fixing bug 394275. Fix problem with UTF16 to UTF8 character conversions when dealing with broken UTF16 characters. r+sr=jonas@sicking.cc

This commit is contained in:
jst%mozilla.org 2007-09-07 20:28:27 +00:00
Родитель f4c26907b8
Коммит c88ff4b755
1 изменённых файлов: 18 добавлений и 5 удалений

Просмотреть файл

@ -603,9 +603,16 @@ class ConvertUTF16toUTF8
++p;
if (p == end)
{
NS_ERROR("Surrogate pair split between fragments");
mBuffer = out;
return N;
// Treat broken characters as the Unicode
// replacement character 0xFFFD (0xEFBFBD in
// UTF-8)
*out++ = 0xEF;
*out++ = 0xBF;
*out++ = 0xBD;
NS_WARNING("String ending in half a surrogate pair!");
break;
}
c = *p;
@ -692,8 +699,14 @@ class CalculateUTF8Size
++p;
if (p == end)
{
NS_ERROR("Surrogate pair split between fragments");
return N;
// Treat broken characters as the Unicode
// replacement character 0xFFFD (0xEFBFBD in
// UTF-8)
mSize += 3;
NS_WARNING("String ending in half a surrogate pair!");
break;
}
c = *p;