From e7abbc7bf3ab06359b2847b1e1a46c38d8bc6581 Mon Sep 17 00:00:00 2001 From: Marc Mutz Date: Tue, 7 Jan 2025 11:37:11 +0100 Subject: [PATCH] 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.9 6.8 6.5 6.2 5.15 Fixes: QTBUG-132597 Change-Id: Ia7a37f714f834191b07420d31ca9024702b537cc Reviewed-by: Ivan Solovev Reviewed-by: Thiago Macieira --- src/corelib/io/qtemporaryfile.cpp | 2 +- tests/auto/corelib/io/qtemporarydir/tst_qtemporarydir.cpp | 1 + tests/auto/corelib/io/qtemporaryfile/tst_qtemporaryfile.cpp | 1 + 3 files changed, 3 insertions(+), 1 deletion(-) diff --git a/src/corelib/io/qtemporaryfile.cpp b/src/corelib/io/qtemporaryfile.cpp index 6fb543d8696..0d69d3835a0 100644 --- a/src/corelib/io/qtemporaryfile.cpp +++ b/src/corelib/io/qtemporaryfile.cpp @@ -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 diff --git a/tests/auto/corelib/io/qtemporarydir/tst_qtemporarydir.cpp b/tests/auto/corelib/io/qtemporarydir/tst_qtemporarydir.cpp index 737317a8fb3..8b9b2cfb1ae 100644 --- a/tests/auto/corelib/io/qtemporarydir/tst_qtemporarydir.cpp +++ b/tests/auto/corelib/io/qtemporarydir/tst_qtemporarydir.cpp @@ -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(); diff --git a/tests/auto/corelib/io/qtemporaryfile/tst_qtemporaryfile.cpp b/tests/auto/corelib/io/qtemporaryfile/tst_qtemporaryfile.cpp index ce8028e6d04..e57cc732ee2 100644 --- a/tests/auto/corelib/io/qtemporaryfile/tst_qtemporaryfile.cpp +++ b/tests/auto/corelib/io/qtemporaryfile/tst_qtemporaryfile.cpp @@ -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";