QInputControl: accept surrogate category character

See also https://unicodebook.readthedocs.io/unicode_encodings.html#utf-16-surrogate-pairs .

Fixes: QTBUG-89184
Change-Id: I04eff7f42f0030346603a7b31e4ac854a477030c
Reviewed-by: Lars Knoll <lars.knoll@qt.io>
(cherry picked from commit e688b99995b8c624dbcea296c99fb89262d29e15)
Reviewed-by: Qt Cherry-pick Bot <cherrypick_bot@qt-project.org>
This commit is contained in:
Liang Qi 2020-12-17 17:22:48 +01:00 committed by Qt Cherry-pick Bot
parent 562fb69d75
commit 51e940260a
2 changed files with 49 additions and 0 deletions

View File

@ -79,6 +79,9 @@ bool QInputControl::isAcceptableInput(const QKeyEvent *event) const
if (c.category() == QChar::Other_PrivateUse)
return true;
if (c.isHighSurrogate() && text.length() > 1 && text.at(1).isLowSurrogate())
return true;
if (m_type == TextEdit && c == QLatin1Char('\t'))
return true;

View File

@ -58,6 +58,52 @@ void tst_QInputControl::isAcceptableInput_data()
QTest::newRow("printable-latin-with-ctrl-shift") << QString(QLatin1Char('a')) << Qt::KeyboardModifiers(Qt::ControlModifier | Qt::ShiftModifier) << false;
QTest::newRow("printable-hebrew") << QString(QChar(0x2135)) << Qt::KeyboardModifiers() << true;
QTest::newRow("private-use-area") << QString(QChar(0xE832)) << Qt::KeyboardModifiers() << true;
QTest::newRow("good-surrogate-0") << QString::fromUtf16(u"\U0001F44D") << Qt::KeyboardModifiers() << true;
{
const QChar data[] = { QChar(0xD800), QChar(0xDC00) };
const QString str = QString(data, 2);
QTest::newRow("good-surrogate-1") << str << Qt::KeyboardModifiers() << true;
}
{
const QChar data[] = { QChar(0xD800), QChar(0xDFFF) };
const QString str = QString(data, 2);
QTest::newRow("good-surrogate-2") << str << Qt::KeyboardModifiers() << true;
}
{
const QChar data[] = { QChar(0xDBFF), QChar(0xDC00) };
const QString str = QString(data, 2);
QTest::newRow("good-surrogate-3") << str << Qt::KeyboardModifiers() << true;
}
{
const QChar data[] = { QChar(0xDBFF), QChar(0xDFFF) };
const QString str = QString(data, 2);
QTest::newRow("good-surrogate-4") << str << Qt::KeyboardModifiers() << true;
}
{
const QChar data[] = { QChar(0xD7FF), QChar(0xDC00) };
const QString str = QString(data, 2);
QTest::newRow("bad-surrogate-1") << str << Qt::KeyboardModifiers() << false;
}
{
const QChar data[] = { QChar(0xD7FF), QChar(0xDFFF) };
const QString str = QString(data, 2);
QTest::newRow("bad-surrogate-2") << str << Qt::KeyboardModifiers() << false;
}
{
const QChar data[] = { QChar(0xDC00), QChar(0xDC00) };
const QString str = QString(data, 2);
QTest::newRow("bad-surrogate-3") << str << Qt::KeyboardModifiers() << false;
}
{
const QChar data[] = { QChar(0xD800), QChar(0xE000) };
const QString str = QString(data, 2);
QTest::newRow("bad-surrogate-4") << str << Qt::KeyboardModifiers() << false;
}
{
const QChar data[] = { QChar(0xD800) };
const QString str = QString(data, 1);
QTest::newRow("bad-surrogate-5") << str << Qt::KeyboardModifiers() << false;
}
QTest::newRow("multiple-printable") << QStringLiteral("foobar") << Qt::KeyboardModifiers() << true;
QTest::newRow("rlm") << QString(QChar(0x200F)) << Qt::KeyboardModifiers() << true;
QTest::newRow("rlm-with-ctrl") << QString(QChar(0x200F)) << Qt::KeyboardModifiers(Qt::ControlModifier) << true;