QDir: Do not assume that root ends with a slash

Root can also be "//server"

Task-number: QTBUG-35402
Change-Id: I25250b7dcb10cba7b676a0c88b64a402494d7481
Reviewed-by: Friedemann Kleint <Friedemann.Kleint@digia.com>
Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
bb10
Orgad Shaneh 2013-12-04 14:33:25 +02:00 committed by The Qt Project
parent debe31e047
commit b5241296f8
2 changed files with 9 additions and 4 deletions

View File

@ -716,11 +716,12 @@ QString QDir::absoluteFilePath(const QString &fileName) const
return fileName;
d->resolveAbsoluteEntry();
const QString absoluteDirPath = d->absoluteDirEntry.filePath();
if (fileName.isEmpty())
return d->absoluteDirEntry.filePath();
if (!d->absoluteDirEntry.isRoot())
return d->absoluteDirEntry.filePath() % QLatin1Char('/') % fileName;
return d->absoluteDirEntry.filePath() % fileName;
return absoluteDirPath;
if (!absoluteDirPath.endsWith(QLatin1Char('/')))
return absoluteDirPath % QLatin1Char('/') % fileName;
return absoluteDirPath % fileName;
}
/*!

View File

@ -1098,6 +1098,10 @@ void tst_QDir::absoluteFilePath_data()
QTest::newRow("2") << "/" << "passwd" << "/passwd";
QTest::newRow("3") << "relative" << "path" << QDir::currentPath() + "/relative/path";
QTest::newRow("4") << "" << "" << QDir::currentPath();
#ifdef Q_OS_WIN
QTest::newRow("5") << "//machine" << "share" << "//machine/share";
#endif
QTest::newRow("resource") << ":/prefix" << "foo.bar" << ":/prefix/foo.bar";
}