diff options
author | Konstantin Ritt <ritt.ks@gmail.com> | 2013-06-16 11:28:11 +0300 |
---|---|---|
committer | The Qt Project <gerrit-noreply@qt-project.org> | 2013-07-11 12:26:33 +0200 |
commit | 6326b4e622942c701af90e992d7a58f59be41fa2 (patch) | |
tree | 227ba46168ab6b820a1e276fb3527d01c825c919 | |
parent | c504d5b8047483e87fd1cfad2c2824353310c5da (diff) |
QString::normalize(): Fix assertion in some corner case
Don't assume `from` is 0 and the string always starts with a starter code point.
This has been fixed for 5.0 as part of Unicode Data & Algorithms update
(qtbase:46b78113b22428e6f8540193fcf0e00591dbd724).
Task-number: QTBUG-30931
Change-Id: I2030aaf831ebe619b980e55e98d5f5a366dbe3ed
Reviewed-by: Lars Knoll <lars.knoll@digia.com>
-rw-r--r-- | src/corelib/tools/qchar.cpp | 7 | ||||
-rw-r--r-- | tests/auto/qchar/tst_qchar.cpp | 14 |
2 files changed, 17 insertions, 4 deletions
diff --git a/src/corelib/tools/qchar.cpp b/src/corelib/tools/qchar.cpp index 49cc2430e3..fb410262fb 100644 --- a/src/corelib/tools/qchar.cpp +++ b/src/corelib/tools/qchar.cpp @@ -1550,8 +1550,8 @@ static void composeHelper(QString *str, QChar::UnicodeVersion version, int from) return; // the loop can partly ignore high Unicode as all ligatures are in the BMP - int starter = 0; - int lastCombining = 0; + int starter = -2; // to prevent starter == pos - 1 + int lastCombining = 255; // to prevent combining > lastCombining int pos = from; while (pos < s.length()) { uint uc = s.at(pos).unicode(); @@ -1570,8 +1570,7 @@ static void composeHelper(QString *str, QChar::UnicodeVersion version, int from) continue; } int combining = p->combiningClass; - if (starter == pos - 1 || combining > lastCombining) { - Q_ASSERT(starter >= from); + if ((starter == pos - 1 || combining > lastCombining) && starter >= from) { // allowed to form ligature with S QChar ligature = ligatureHelper(s.at(starter).unicode(), uc); if (ligature.unicode()) { diff --git a/tests/auto/qchar/tst_qchar.cpp b/tests/auto/qchar/tst_qchar.cpp index 89fa34f22c..a4ad8e9fc1 100644 --- a/tests/auto/qchar/tst_qchar.cpp +++ b/tests/auto/qchar/tst_qchar.cpp @@ -694,6 +694,20 @@ void tst_QChar::normalization_manual() QVERIFY(composed.normalized(QString::NormalizationForm_KD) == decomposed); QVERIFY(composed.normalized(QString::NormalizationForm_KC) == decomposed); } + { + QString composed; + composed += QChar(0x0061); + composed += QChar(0x00f2); + QString decomposed; + decomposed += QChar(0x0061); + decomposed += QChar(0x006f); + decomposed += QChar(0x0300); + + QVERIFY(decomposed.normalized(QString::NormalizationForm_D) == decomposed); + QVERIFY(decomposed.normalized(QString::NormalizationForm_C) == composed); + QVERIFY(decomposed.normalized(QString::NormalizationForm_KD) == decomposed); + QVERIFY(decomposed.normalized(QString::NormalizationForm_KC) == composed); + } } void tst_QChar::normalizationCorrections() |