Fix incomplete Windows devices name verification

Extend Windows devices name pattern with missing names and arbitrary
filename extension.
List all devices in the corresponding error message.

Former devices name verification on attempt of adding a file allowed
to proceed with forbidden name which caused Qt Creator crash.

Change-Id: I9abb0210c4140c7188c909fbb809808cb1d50210
Reviewed-by: Oswald Buddenhagen <oswald.buddenhagen@gmx.de>
Reviewed-by: Friedemann Kleint <Friedemann.Kleint@qt.io>
Reviewed-by: hjk <hjk@qt.io>
This commit is contained in:
Nikolay Panov
2020-01-03 21:58:56 +04:00
parent e941e0cac7
commit 5103cd0f69

View File

@@ -41,21 +41,21 @@
namespace Utils {
#define WINDOWS_DEVICES "CON|AUX|PRN|COM1|COM2|LPT1|LPT2|NUL"
#define WINDOWS_DEVICES_PATTERN "(CON|AUX|PRN|NUL|COM[1-9]|LPT[1-9])(\\..*)?"
// Naming a file like a device name will break on Windows, even if it is
// "com1.txt". Since we are cross-platform, we generally disallow such file
// names.
static const QRegExp &windowsDeviceNoSubDirPattern()
{
static const QRegExp rc(QLatin1String(WINDOWS_DEVICES), Qt::CaseInsensitive);
static const QRegExp rc(QLatin1String(WINDOWS_DEVICES_PATTERN), Qt::CaseInsensitive);
QTC_ASSERT(rc.isValid(), return rc);
return rc;
}
static const QRegExp &windowsDeviceSubDirPattern()
{
static const QRegExp rc(QLatin1String(".*[/\\\\](" WINDOWS_DEVICES ")"), Qt::CaseInsensitive);
static const QRegExp rc(QLatin1String(".*[/\\\\]" WINDOWS_DEVICES_PATTERN), Qt::CaseInsensitive);
QTC_ASSERT(rc.isValid(), return rc);
return rc;
}
@@ -140,8 +140,10 @@ bool FileNameValidatingLineEdit::validateFileName(const QString &name,
matchesWinDevice = windowsDeviceSubDirPattern().exactMatch(name);
if (matchesWinDevice) {
if (errorMessage)
*errorMessage = tr("Name matches MS Windows device. (%1).").
arg(windowsDeviceNoSubDirPattern().pattern().replace(QLatin1Char('|'), QLatin1Char(',')));
*errorMessage = tr("Name matches MS Windows device"
" (CON, AUX, PRN, NUL,"
" COM1, COM2, ..., COM9,"
" LPT1, LPT2, ..., LPT9)");
return false;
}
return true;