From 5a10cf060e6c843f05d8bd820a4be4bb08f277ec Mon Sep 17 00:00:00 2001 From: Andy Shaw Date: Tue, 21 Nov 2017 13:05:45 +0100 Subject: Prevent invalid characters being entered at the appropriate times When a validator does not allow for certain characters to be entered, then it should not allow these to be entered in even if an input mask is set. This fixes a regression introduced in 1b21b73e89942d567c90a17a3bf7a7ecae3de258. The test modified is because this is in fact a general limitation when combining validators and input masks, when a separator is used. Whereas the original patch did allow this to be possible, this is now not possible again. Task-number: QTBUG-64616 Change-Id: Ic6a3f40a9faa7c04abc055cfc2752044fddd33a0 Reviewed-by: Frederik Gladhorn Reviewed-by: Robin Burchell --- src/quick/items/qquicktextinput.cpp | 36 +++++++++--------------------------- 1 file changed, 9 insertions(+), 27 deletions(-) (limited to 'src/quick/items/qquicktextinput.cpp') diff --git a/src/quick/items/qquicktextinput.cpp b/src/quick/items/qquicktextinput.cpp index 28b089da49..0c1cb7a146 100644 --- a/src/quick/items/qquicktextinput.cpp +++ b/src/quick/items/qquicktextinput.cpp @@ -1077,7 +1077,8 @@ void QQuickTextInputPrivate::checkIsValid() Q_Q(QQuickTextInput); ValidatorState state = hasAcceptableInput(m_text); - m_validInput = state != InvalidInput; + if (!m_maskData) + m_validInput = state != InvalidInput; if (state != AcceptableInput) { if (m_acceptableInput) { m_acceptableInput = false; @@ -3530,11 +3531,15 @@ bool QQuickTextInputPrivate::finishChange(int validateFromState, bool update, bo #if QT_CONFIG(validator) if (m_validator) { QString textCopy = m_text; + if (m_maskData) + textCopy = maskString(0, m_text, true); int cursorCopy = m_cursor; QValidator::State state = m_validator->validate(textCopy, cursorCopy); + if (m_maskData) + textCopy = m_text; m_validInput = state != QValidator::Invalid; m_acceptableInput = state == QValidator::Acceptable; - if (m_validInput) { + if (m_validInput && !m_maskData) { if (m_text != textCopy) { internalSetText(textCopy, cursorCopy); return true; @@ -3543,31 +3548,8 @@ bool QQuickTextInputPrivate::finishChange(int validateFromState, bool update, bo } } #endif - - if (m_maskData) { - m_validInput = true; - if (m_text.length() != m_maxLength) { - m_validInput = false; - m_acceptableInput = false; - } else { - for (int i = 0; i < m_maxLength; ++i) { - if (m_maskData[i].separator) { - if (m_text.at(i) != m_maskData[i].maskChar) { - m_validInput = false; - m_acceptableInput = false; - break; - } - } else { - if (!isValidInput(m_text.at(i), m_maskData[i].maskChar)) { - m_acceptableInput = false; - if (m_text.at(i) != m_blank) - m_validInput = false; - break; - } - } - } - } - } + if (m_maskData) + checkIsValid(); if (validateFromState >= 0 && wasValidInput && !m_validInput) { if (m_transactions.count()) -- cgit v1.2.3