Skip to content

Commit

Permalink
Merge pull request #5 from special/master
Browse files Browse the repository at this point in the history
[mlocale] Prevent assertion under MLocale::indexBucket with malformed input
  • Loading branch information
special committed Jul 3, 2014
2 parents 607c972 + 231fd04 commit 91bc3ef
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 2 deletions.
3 changes: 2 additions & 1 deletion src/micuconversions.cpp
Expand Up @@ -30,7 +30,8 @@ namespace ML10N {

icu::UnicodeString MIcuConversions::qStringToUnicodeString(const QString &sourceStr)
{
return UnicodeString(static_cast<const UChar *>(sourceStr.utf16()));
return UnicodeString(static_cast<const UChar *>(sourceStr.utf16()),
sourceStr.length());
}

QString MIcuConversions::unicodeStringToQString(const icu::UnicodeString &sourceStr)
Expand Down
6 changes: 5 additions & 1 deletion src/mlocale.cpp
Expand Up @@ -3986,12 +3986,16 @@ QString MLocale::indexBucket(const QString &str, const QStringList &buckets, con
MIcuConversions::unicodeStringToQString(
MIcuConversions::qStringToUnicodeString(str).toUpper(
d->getCategoryLocale(MLocale::MLcCollate)));
if (strUpperCase.isEmpty())
return strUpperCase;
QString firstCharacter;
if (strUpperCase.at(0).isHighSurrogate())
if (strUpperCase.at(0).isHighSurrogate() && strUpperCase.length() > 1)
firstCharacter = strUpperCase.at(0) + strUpperCase.at(1);
else
firstCharacter = strUpperCase.at(0);
firstCharacter = MLocalePrivate::removeAccents(firstCharacter);
if (firstCharacter.isEmpty())
return firstCharacter;
// removing the accents as above also does expansions
// like “㈠ → (一)”. If this happened, take the first character
// of the expansion:
Expand Down

0 comments on commit 91bc3ef

Please sign in to comment.