From 5103cd0f69535982b44d27373edd0f4e87bba4f8 Mon Sep 17 00:00:00 2001 From: Nikolay Panov Date: Fri, 3 Jan 2020 21:58:56 +0400 Subject: [PATCH] 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 Reviewed-by: Friedemann Kleint Reviewed-by: hjk --- src/libs/utils/filenamevalidatinglineedit.cpp | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/src/libs/utils/filenamevalidatinglineedit.cpp b/src/libs/utils/filenamevalidatinglineedit.cpp index 271f325a219..555cdc1a8d0 100644 --- a/src/libs/utils/filenamevalidatinglineedit.cpp +++ b/src/libs/utils/filenamevalidatinglineedit.cpp @@ -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;