diff --git a/tools/nitpick/src/AWSInterface.cpp b/tools/nitpick/src/AWSInterface.cpp index 59be26c383..8203c41005 100644 --- a/tools/nitpick/src/AWSInterface.cpp +++ b/tools/nitpick/src/AWSInterface.cpp @@ -27,9 +27,29 @@ void AWSInterface::createWebPageFromResults(const QString& testResults, const QString& workingDirectory, QCheckBox* updateAWSCheckBox, QLineEdit* urlLineEdit) { - _testResults = testResults; _workingDirectory = workingDirectory; + // Verify filename is in correct format + // For example `D:/tt/TestResults--2019-02-10_17-30-57(local)[DESKTOP-6BO62Q9].zip` + QStringList parts = testResults.split('/'); + QString zipFilename = parts[parts.length() - 1]; + _zipFolderName = _workingDirectory + "/" + zipFilename.split('.')[0]; + + QStringList zipFolderNameParts = zipFilename.split(QRegExp("[\\(\\)\\[\\]]"), QString::SkipEmptyParts); + bool a = QRegularExpression("TestResults--\\d{4}(-\\d\\d){2}_\\d\\d(-\\d\\d){2}").match(zipFolderNameParts[0]).hasMatch(); + bool b = QRegularExpression("\\w").match(zipFolderNameParts[1]).hasMatch(); + bool c = QRegularExpression("\\w").match(zipFolderNameParts[2]).hasMatch(); + + if (!QRegularExpression("TestResults--\\d{4}(-\\d\\d){2}_\\d\\d(-\\d\\d){2}").match(zipFolderNameParts[0]).hasMatch() || + !QRegularExpression("\\w").match(zipFolderNameParts[1]).hasMatch() || // build (local, build number or PR number) + !QRegularExpression("\\w").match(zipFolderNameParts[2]).hasMatch() // machine name + ) { + QMessageBox::critical(0, "Filename is in wrong format", "'" + zipFilename + "' is not in nitpick format"); + return; + } + + _testResults = testResults; + _urlLineEdit = urlLineEdit; _urlLineEdit->setEnabled(false); @@ -48,10 +68,8 @@ void AWSInterface::extractTestFailuresFromZippedFolder() { // For a test results zip file called `D:/tt/TestResults--2018-10-02_16-54-11(9426)[DESKTOP-PMKNLSQ].zip` // the folder will be called `TestResults--2018-10-02_16-54-11(9426)[DESKTOP-PMKNLSQ]` // and, this folder will be in the working directory - QStringList parts = _testResults.split('/'); - QString zipFolderName = _workingDirectory + "/" + parts[parts.length() - 1].split('.')[0]; - if (QDir(zipFolderName).exists()) { - QDir dir = zipFolderName; + if (QDir(_zipFolderName).exists()) { + QDir dir = _zipFolderName; dir.removeRecursively(); } diff --git a/tools/nitpick/src/AWSInterface.h b/tools/nitpick/src/AWSInterface.h index 63c48580f5..7a06adea41 100644 --- a/tools/nitpick/src/AWSInterface.h +++ b/tools/nitpick/src/AWSInterface.h @@ -49,6 +49,7 @@ public: private: QString _testResults; + QString _zipFolderName; QString _workingDirectory; QString _resultsFolder; QString _htmlFailuresFolder;