diff --git a/sources/titleblock/qettemplateeditor.cpp b/sources/titleblock/qettemplateeditor.cpp index 9dd025132..3a316f15b 100644 --- a/sources/titleblock/qettemplateeditor.cpp +++ b/sources/titleblock/qettemplateeditor.cpp @@ -776,7 +776,20 @@ bool QETTitleBlockTemplateEditor::saveAs(const TitleBlockTemplateLocation &locat elmt.setAttribute("name", location.name()); doc.appendChild(elmt); - collection -> setTemplateXmlDescription(location.name(), elmt); + if (!collection -> setTemplateXmlDescription(location.name(), elmt)) { + // Report the failure instead of marking the template "saved" + // regardless (bugtracker #251) -- this return value used to + // be discarded here. + QET::QetMessageBox::critical( + this, + tr("Erreur", "message box title"), + tr( + "Impossible d'enregistrer le modèle « %1 ».", + "message box content - %1 is a title block template name" + ).arg(location.name()) + ); + return(false); + } opened_from_file_ = false; location_ = location; @@ -880,6 +893,21 @@ bool QETTitleBlockTemplateEditor::saveAs() if (location.isValid()) { return(saveAs(location)); } + if (!location.name().isEmpty()) { + // The name was rejected (e.g. contains a path separator or + // other filesystem-reserved character) rather than the user + // cancelling the dialog -- say so instead of silently doing + // nothing (bugtracker #251). + QET::QetMessageBox::critical( + this, + tr("Erreur", "message box title"), + tr( + "Le nom « %1 » n'est pas valide : il ne doit pas contenir " + "les caractères suivants : \\ / : * ? \" < > |", + "message box content - %1 is the rejected template name" + ).arg(location.name()) + ); + } return(false); } diff --git a/sources/titleblock/templatelocation.cpp b/sources/titleblock/templatelocation.cpp index 4387d6412..6f01ce591 100644 --- a/sources/titleblock/templatelocation.cpp +++ b/sources/titleblock/templatelocation.cpp @@ -92,7 +92,13 @@ void TitleBlockTemplateLocation::setName(const QString &name) { */ bool TitleBlockTemplateLocation::isValid() const { - return(!name_.isEmpty()); + // The name becomes (part of) a filename on disk (see + // TitleBlockTemplatesFilesCollection::toFileName()). A name containing + // a path separator or another filesystem-reserved character silently + // fails to save instead of erroring, because it turns into an + // unintended subpath rather than a plain filename (bugtracker #251). + static const QRegularExpression invalid_chars_re(QStringLiteral("[\\\\/:*?\"<>|]")); + return(!name_.isEmpty() && !name_.contains(invalid_chars_re)); } /**