Bug 1026397 part.2 Shouldn't separate input string between a surrogate pair at handling maxlength r=smontagu+ehsan

This commit is contained in:
Masayuki Nakano 2014-06-21 12:17:48 +09:00
parent b65f0775f7
commit 5fb53ba72b

View File

@ -1247,10 +1247,20 @@ nsTextEditRules::TruncateInsertionIfNeeded(Selection* aSelection,
}
else
{
int32_t inCount = aOutString->Length();
if (inCount + resultingDocLength > aMaxLength)
{
aOutString->Truncate(aMaxLength - resultingDocLength);
int32_t oldLength = aOutString->Length();
if (oldLength + resultingDocLength > aMaxLength) {
int32_t newLength = aMaxLength - resultingDocLength;
MOZ_ASSERT(newLength > 0);
char16_t newLastChar = aOutString->CharAt(newLength - 1);
char16_t removingFirstChar = aOutString->CharAt(newLength);
// Don't separate the string between a surrogate pair.
if (NS_IS_HIGH_SURROGATE(newLastChar) &&
NS_IS_LOW_SURROGATE(removingFirstChar)) {
newLength--;
}
// XXX What should we do if we're removing IVS and its preceding
// character won't be removed?
aOutString->Truncate(newLength);
if (aTruncated) {
*aTruncated = true;
}