Commit 47733e88 authored by Peter Simonsson's avatar Peter Simonsson

Don't allow spaces in ident and nick inputs

As the IRC protocol doesn't handle spaces in nicks or idents don't allow
the user add them to the input.

BUG: 422146
parent af7586fc
......@@ -20,6 +20,7 @@
#include <QPushButton>
#include <KStandardGuiItem>
#include <QVBoxLayout>
#include <QRegularExpressionValidator>
#include <algorithm>
......@@ -99,6 +100,12 @@ namespace Konversation
// set the suffix for the inactivity time spinbox
m_awayInactivitySpin->setSuffix(ki18np(" minute", " minutes"));
// Don't allow spaces in username or nicks
const QRegularExpression noSpaceRx(QStringLiteral("\\S+"));
auto *validator = new QRegularExpressionValidator(noSpaceRx, this);
m_loginEdit->setValidator(validator);
m_nicknameLBox->lineEdit()->setValidator(validator);
// set values for the widgets
updateIdentity(0);
......@@ -347,6 +354,20 @@ namespace Konversation
tabWidget->setCurrentIndex(0);
m_nicknameLBox->lineEdit()->setFocus();
return false;
} else {
for(const QString &nick : m_nicknameLBox->items())
{
if(nick.contains(QLatin1Char(' ')))
{
KMessageBox::error(this, i18n("Nicks must not contain spaces."));
bool block = m_identityCBox->blockSignals(true);
m_identityCBox->setCurrentIndex(m_identityCBox->findText(m_currentIdentity->getName()));
m_identityCBox->blockSignals(block);
tabWidget->setCurrentIndex(0);
m_nicknameLBox->lineEdit()->setFocus();
return false;
}
}
}
if(m_realNameEdit->text().isEmpty())
......@@ -360,6 +381,17 @@ namespace Konversation
return false;
}
if(!m_loginEdit->hasAcceptableInput())
{
KMessageBox::error(this, i18n("Ident must not contain spaces."));
bool block = m_identityCBox->blockSignals(true);
m_identityCBox->setCurrentIndex(m_identityCBox->findText(m_currentIdentity->getName()));
m_identityCBox->blockSignals(block);
tabWidget->setCurrentIndex(2);
m_loginEdit->setFocus();
return false;
}
return true;
}
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment