QUrl::fromUserInput: fix handling of files with a ':' in the name
QUrl::isRelative(str) would be false for such files, so first check for file existence before doing any URL parsing. Change-Id: I51b6229251ad94877ac408b2f8018456d3e10a36 Reviewed-by: Shawn Rutledge <shawn.rutledge@qt.io> Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
This commit is contained in:
parent
391e3aeef4
commit
035e0eafa6
@ -4170,12 +4170,15 @@ QUrl QUrl::fromUserInput(const QString &userInput, const QString &workingDirecto
|
||||
return url;
|
||||
}
|
||||
|
||||
const QFileInfo fileInfo(QDir(workingDirectory), userInput);
|
||||
if (fileInfo.exists()) {
|
||||
return QUrl::fromLocalFile(fileInfo.absoluteFilePath());
|
||||
}
|
||||
|
||||
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(userInput)) {
|
||||
QFileInfo fileInfo(QDir(workingDirectory), userInput);
|
||||
if ((options & AssumeLocalFile) || fileInfo.exists())
|
||||
return QUrl::fromLocalFile(fileInfo.absoluteFilePath());
|
||||
if ((options & AssumeLocalFile) && url.isRelative() && !QDir::isAbsolutePath(userInput)) {
|
||||
return QUrl::fromLocalFile(fileInfo.absoluteFilePath());
|
||||
}
|
||||
|
||||
return fromUserInput(trimmedString);
|
||||
|
@ -3088,7 +3088,7 @@ void tst_QUrl::fromUserInputWithCwd_data()
|
||||
}
|
||||
|
||||
// Existing files
|
||||
for (const char *fileName : {"file.txt", "file#a.txt", "file .txt", "file.txt "}) {
|
||||
for (const char *fileName : {"file.txt", "file#a.txt", "file .txt", "file.txt ", "file:colon.txt"}) {
|
||||
const QString filePath = base + '/' + fileName;
|
||||
QFile file(filePath);
|
||||
QVERIFY2(file.open(QIODevice::WriteOnly), qPrintable(filePath));
|
||||
|
Loading…
Reference in New Issue
Block a user