summaryrefslogtreecommitdiffstats
path: root/src/gui
diff options
context:
space:
mode:
authorFrédéric Brière <fbriere@fbriere.net>2020-03-31 17:24:27 -0400
committerFrédéric Brière <fbriere@fbriere.net>2020-03-31 18:04:14 -0400
commitba8292d0fb08d39b0d8b9913889ffd589821b070 (patch)
tree8f70c3fe70e9f7026a1aa8bf74f6aec6667e5b31 /src/gui
parentea00ce2f9d24ade8bcf8736a31516b41511e6233 (diff)
downloadtwinkle-ba8292d0fb08d39b0d8b9913889ffd589821b070.tar
twinkle-ba8292d0fb08d39b0d8b9913889ffd589821b070.tar.gz
twinkle-ba8292d0fb08d39b0d8b9913889ffd589821b070.tar.lz
twinkle-ba8292d0fb08d39b0d8b9913889ffd589821b070.tar.xz
twinkle-ba8292d0fb08d39b0d8b9913889ffd589821b070.zip
Relax GetProfileNameForm validator to only check individual characters
QRegExpValidator can be somewhat user-unfriendly, as it will prevent characters from being input, or even deleted, while leaving the user in the dark as to what is going on. Retricting the set of characters allowed shouldn't pose a problem if we make a mention of this on the form. Checking for a leading "." or "@", however, is better left at submission time, with an explicit error message in that case.
Diffstat (limited to 'src/gui')
-rw-r--r--src/gui/getprofilenameform.cpp26
1 files changed, 22 insertions, 4 deletions
diff --git a/src/gui/getprofilenameform.cpp b/src/gui/getprofilenameform.cpp
index 19e3a62..f2042c5 100644
--- a/src/gui/getprofilenameform.cpp
+++ b/src/gui/getprofilenameform.cpp
@@ -29,8 +29,8 @@ GetProfileNameForm::~GetProfileNameForm()
void GetProfileNameForm::init()
{
- // Letters, digits, underscore, minus
- QRegExp rxFilenameChars("[\\w\\-][\\w\\-@\\.]*");
+ // Letters, digits, underscore, minus, "@" and period
+ QRegExp rxFilenameChars("[\\w\\-@\\.]*");
// Set validators
// USER
@@ -39,7 +39,25 @@ void GetProfileNameForm::init()
void GetProfileNameForm::validate()
{
- if (profileLineEdit->text().isEmpty()) return;
+ QString profileName = profileLineEdit->text();
+
+ if (profileName.isEmpty()) return;
+
+ // Check for anything that was let through by the validator
+ QRegExp rxFilename("^[\\w\\-][\\w\\-@\\.]*$");
+ if (!rxFilename.exactMatch(profileName)) {
+ QMessageBox::critical(this, PRODUCT_NAME,
+ tr("Invalid profile name: %1").arg(profileName)
+ // While this would be better suited as informativeText,
+ // Qt wouldn't take it into account when sizing the box
+ // (see http://apocalyptech.com/linux/qt/qmessagebox/)
+ + QString("\n\n") + tr(
+ "Allowed characters are: letters, digits, '-', '_', '.' and '@'.\n"
+ "Furthermore, the initial character cannot be '.' or '@'."
+ ));
+
+ return;
+ }
// Find the .twinkle directory in HOME
QDir d = QDir::home();
@@ -49,7 +67,7 @@ void GetProfileNameForm::validate()
reject();
}
- QString filename = profileLineEdit->text();
+ QString filename = profileName;
filename.append(USER_FILE_EXT);
QString fullname = d.filePath(filename);
if (QFile::exists(fullname)) {