Merge pull request #717 from ispyisail/fix/titleblock-invalid-name-bug251

Fix bugtracker #251: title block template with slash in name fails silently
There are some characters that are not allowed in filenames.
Absolutely correct to mark a filename containing (one of) them as invalid!
This commit is contained in:
plc-user
2026-08-11 12:52:52 +02:00
committed by GitHub
2 changed files with 36 additions and 2 deletions
+29 -1
View File
@@ -776,7 +776,20 @@ bool QETTitleBlockTemplateEditor::saveAs(const TitleBlockTemplateLocation &locat
elmt.setAttribute("name", location.name()); elmt.setAttribute("name", location.name());
doc.appendChild(elmt); 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; opened_from_file_ = false;
location_ = location; location_ = location;
@@ -880,6 +893,21 @@ bool QETTitleBlockTemplateEditor::saveAs()
if (location.isValid()) { if (location.isValid()) {
return(saveAs(location)); 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); return(false);
} }
+7 -1
View File
@@ -92,7 +92,13 @@ void TitleBlockTemplateLocation::setName(const QString &name) {
*/ */
bool TitleBlockTemplateLocation::isValid() const 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));
} }
/** /**