QLineEdit: Fix length calculation for input mask "\\\\"
Consider the raw string \\\\. The previous algorithm would consider the last 3 \ to be escaped because the previous character is a \ and thus calculating a maxLength of 3. But this should be treated as two escaped \ with a maxLength of 2. Change-Id: I6c4b8d090a2e1c6e85195d5920ce8b80aea1bc2d Reviewed-by: Marc Mutz <marc.mutz@kdab.com>
This commit is contained in:
parent
bdca35e815
commit
7051572618
@ -973,12 +973,20 @@ void QWidgetLineControl::parseInputMask(const QString &maskFields)
|
||||
// calculate m_maxLength / m_maskData length
|
||||
m_maxLength = 0;
|
||||
QChar c = 0;
|
||||
bool escaped = false;
|
||||
for (int i=0; i<m_inputMask.length(); i++) {
|
||||
c = m_inputMask.at(i);
|
||||
if (i > 0 && m_inputMask.at(i-1) == QLatin1Char('\\')) {
|
||||
m_maxLength++;
|
||||
continue;
|
||||
if (escaped) {
|
||||
++m_maxLength;
|
||||
escaped = false;
|
||||
continue;
|
||||
}
|
||||
|
||||
if (c == '\\') {
|
||||
escaped = true;
|
||||
continue;
|
||||
}
|
||||
|
||||
if (c != QLatin1Char('\\') && c != QLatin1Char('!') &&
|
||||
c != QLatin1Char('<') && c != QLatin1Char('>') &&
|
||||
c != QLatin1Char('{') && c != QLatin1Char('}') &&
|
||||
|
@ -3106,7 +3106,6 @@ void tst_QLineEdit::inputMaskAndValidator()
|
||||
|
||||
void tst_QLineEdit::maxLengthAndInputMask()
|
||||
{
|
||||
// Really a test for #30447
|
||||
QLineEdit *testWidget = ensureTestWidget();
|
||||
QVERIFY(testWidget->inputMask().isNull());
|
||||
testWidget->setMaxLength(10);
|
||||
@ -3114,6 +3113,16 @@ void tst_QLineEdit::maxLengthAndInputMask()
|
||||
testWidget->setInputMask(QString());
|
||||
QVERIFY(testWidget->inputMask().isNull());
|
||||
QCOMPARE(testWidget->maxLength(), 10);
|
||||
|
||||
testWidget->setInputMask("XXXX");
|
||||
QCOMPARE(testWidget->maxLength(), 4);
|
||||
|
||||
testWidget->setMaxLength(15);
|
||||
QCOMPARE(testWidget->maxLength(), 4);
|
||||
|
||||
// 8 \ => raw string with 4 \ => input mask with 2 \ => maxLength = 2
|
||||
testWidget->setInputMask("\\\\\\\\");
|
||||
QCOMPARE(testWidget->maxLength(), 2);
|
||||
}
|
||||
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user