# HG changeset patch # User Chris Cannam # Date 1305121287 -3600 # Node ID ee927c1b7941df580e6bb18febfcec464f80eacb # Parent 45bfc5962c334794d7fd83bc5361086bfecfce90 Sanitise template file name; ask for confirmation when overwriting diff -r 45bfc5962c33 -r ee927c1b7941 main/MainWindow.cpp --- a/main/MainWindow.cpp Wed May 11 13:52:00 2011 +0100 +++ b/main/MainWindow.cpp Wed May 11 14:41:27 2011 +0100 @@ -2891,13 +2891,22 @@ tr("Please enter a name for the saved template:")); if (name == "") return; - //!!! sanitise name! - - //!!! check/confirm if target exists! + name.replace(QRegExp("[^\\w\\s\\.\"'-]"), "_"); ResourceFinder rf; QString dir = rf.getResourceSaveDir("templates"); - saveSessionTemplate(QString("%1/%2.svt").arg(dir).arg(name)); + QString filename = QString("%1/%2.svt").arg(dir).arg(name); + if (QFile(filename).exists()) { + if (QMessageBox::warning(this, + tr("Template file exists"), + tr("Template file exists
The template \"%1\" already exists.
Overwrite it?").arg(name),
+ QMessageBox::Ok | QMessageBox::Cancel,
+ QMessageBox::Cancel) != QMessageBox::Ok) {
+ return;
+ }
+ }
+
+ saveSessionTemplate(filename);
}
void