diff --git a/src/corelib/io/qurl.cpp b/src/corelib/io/qurl.cpp index 38f2a708b5..520ad2e5d3 100644 --- a/src/corelib/io/qurl.cpp +++ b/src/corelib/io/qurl.cpp @@ -4170,10 +4170,10 @@ QUrl QUrl::fromUserInput(const QString &userInput, const QString &workingDirecto return url; } - QUrl url = QUrl(trimmedString, QUrl::TolerantMode); + QUrl url = QUrl(userInput, QUrl::TolerantMode); // Check both QUrl::isRelative (to detect full URLs) and QDir::isAbsolutePath (since on Windows drive letters can be interpreted as schemes) - if (url.isRelative() && !QDir::isAbsolutePath(trimmedString)) { - QFileInfo fileInfo(QDir(workingDirectory), trimmedString); + if (url.isRelative() && !QDir::isAbsolutePath(userInput)) { + QFileInfo fileInfo(QDir(workingDirectory), userInput); if ((options & AssumeLocalFile) || fileInfo.exists()) return QUrl::fromLocalFile(fileInfo.absoluteFilePath()); } diff --git a/tests/auto/corelib/io/qurl/tst_qurl.cpp b/tests/auto/corelib/io/qurl/tst_qurl.cpp index e0e6c6f281..ee18151e4a 100644 --- a/tests/auto/corelib/io/qurl/tst_qurl.cpp +++ b/tests/auto/corelib/io/qurl/tst_qurl.cpp @@ -3088,7 +3088,7 @@ void tst_QUrl::fromUserInputWithCwd_data() } // Existing files - for (const char *fileName : {"file.txt", "file#a.txt", "file .txt"}) { + for (const char *fileName : {"file.txt", "file#a.txt", "file .txt", "file.txt "}) { const QString filePath = base + '/' + fileName; QFile file(filePath); QVERIFY2(file.open(QIODevice::WriteOnly), qPrintable(filePath));