QTemporaryFile: fix incorrect info about duplicate placeholders

The docs said only the first placeholder would be considered; in fact,
it considers only the last.

Fix the docs and add a test (also for QTemporaryDir).

Amends b4bb4449aea7592afdb9b9134bb90c40fe29735a.

While 6.6 and earlier are unaffected by the incorrect documentation,
pick this to all active branches in order to verify the behavior is
the same everywhere.

Pick-to: 6.5 6.2 5.15
Fixes: QTBUG-132597
Change-Id: Ia7a37f714f834191b07420d31ca9024702b537cc
Reviewed-by: Ivan Solovev <ivan.solovev@qt.io>
Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
(cherry picked from commit e7abbc7bf3ab06359b2847b1e1a46c38d8bc6581)
Reviewed-by: Qt Cherry-pick Bot <cherrypick_bot@qt-project.org>
(cherry picked from commit 58221c19559541d7da24fa68f05310aeee230e26)
This commit is contained in:
Marc Mutz 2025-01-07 11:37:11 +01:00 committed by Qt Cherry-pick Bot
parent a156bdc9ad
commit 85f77604e3
3 changed files with 3 additions and 1 deletions

View File

@ -610,7 +610,7 @@ QString QTemporaryFilePrivate::defaultTemplateName()
(at least six upper case \c "X" characters), which will be replaced with
the auto-generated portion of the file name. If the file name doesn't
contain \c {"XXXXXX"}, QTemporaryFile will append the generated part to the
file name. Only the first occurrence of \c {"XXXXXX"} will be considered.
file name. Only the last occurrence of \c {"XXXXXX"} will be considered.
\note On Linux, QTemporaryFile will attempt to create unnamed temporary
files. If that succeeds, open() will return true but exists() will be

View File

@ -185,6 +185,7 @@ void tst_QTemporaryDir::fileTemplate_data()
QTest::newRow("4Xsuffix") << "qt_XXXXXX_XXXX" << "qt_" << "_XXXX";
QTest::newRow("4Xprefix") << "qt_XXXX" << "qt_XXXX" << "";
QTest::newRow("5Xprefix") << "qt_XXXXX" << "qt_XXXXX" << "";
QTest::newRow("two placeholders") << "qt_XXXXXX_XXXXXX_" << "qt_XXXXXX_" << "_";
if (QTestPrivate::canHandleUnicodeFileNames()) {
// Test Umlauts (contained in Latin1)
QString prefix = "qt_" + umlautTestText();

View File

@ -180,6 +180,7 @@ void tst_QTemporaryFile::fileTemplate_data()
QTest::newRow("constructor with XXXXX prefix") << "qt_XXXXX" << "qt_XXXXX." << "" << "";
QTest::newRow("constructor with XXXX prefix and suffix") << "qt_XXXX_XXXXXX_XXXX" << "qt_XXXX_" << "_XXXX" << "";
QTest::newRow("constructor with XXXXX prefix and suffix") << "qt_XXXXX_XXXXXX_XXXXX" << "qt_XXXXX_" << "_XXXXX" << "";
QTest::newRow("constructor with two placeholders") << "qt_XXXXXX_XXXXXX_" << "qt_XXXXXX_" << "_" << "";
QTest::newRow("set template, no suffix") << "" << "foo" << "" << "foo";
QTest::newRow("set template, with lowercase XXXXXX") << "" << "qt_" << "xxxxxx" << "qt_XXXXXXxxxxxx";