summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAndy Shaw <andy.shaw@digia.com>2012-04-17 18:30:54 (GMT)
committerQt by Nokia <qt-info@nokia.com>2012-05-16 20:13:40 (GMT)
commitfd2eb070128ab6ef6b5c9343a0921f6b5a0bc041 (patch)
tree8dab8ec2f019cc143d6e123affd044018dfef029
parentfcfd40544f5730f8902544aac5ca5fafec52e5c2 (diff)
downloadQt-fd2eb070128ab6ef6b5c9343a0921f6b5a0bc041.zip
Qt-fd2eb070128ab6ef6b5c9343a0921f6b5a0bc041.tar.gz
Qt-fd2eb070128ab6ef6b5c9343a0921f6b5a0bc041.tar.bz2
Fix cases where functions are called with a drive and no slash
When a file is specified on a path that includes a drive letter followed by a colon but no slash then it didn't always account for the fact that this refers to the current path on that drive. This fixes the problems in completeBaseName(), baseName() and path(). Tests are also added for these three cases and some others too. Task-number: QTBUG-25353 Change-Id: I47a197c6af066f532442ad269be57597ec61303a Reviewed-by: Irfan Omair <irfan.omair@gmail.com> Reviewed-by: Shane Kearns <shane.kearns@accenture.com> (cherry picked from commit cfb44c6528b2518274bf157388832d1d610ce0e4)
-rw-r--r--src/corelib/io/qfilesystementry.cpp18
-rw-r--r--tests/auto/qfileinfo/tst_qfileinfo.cpp26
2 files changed, 34 insertions, 10 deletions
diff --git a/src/corelib/io/qfilesystementry.cpp b/src/corelib/io/qfilesystementry.cpp
index 11b73dd..3ee3a87 100644
--- a/src/corelib/io/qfilesystementry.cpp
+++ b/src/corelib/io/qfilesystementry.cpp
@@ -189,7 +189,7 @@ QString QFileSystemEntry::path() const
if (m_lastSeparator == -1) {
#if defined(Q_OS_WIN) || defined(Q_OS_SYMBIAN)
if (m_filePath.length() >= 2 && m_filePath.at(1) == QLatin1Char(':'))
- return m_filePath.left(2);
+ return QFSFileEngine::currentPath(m_filePath.left(2));
#endif
return QString(QLatin1Char('.'));
}
@@ -205,32 +205,32 @@ QString QFileSystemEntry::path() const
QString QFileSystemEntry::baseName() const
{
findFileNameSeparators();
-#if defined(Q_OS_WIN) || defined(Q_OS_SYMBIAN)
- if (m_lastSeparator == -1 && m_filePath.length() >= 2 && m_filePath.at(1) == QLatin1Char(':'))
- return m_filePath.mid(2);
-#endif
int length = -1;
if (m_firstDotInFileName >= 0) {
length = m_firstDotInFileName;
if (m_lastSeparator != -1) // avoid off by one
length--;
}
+#if defined(Q_OS_WIN)
+ if (m_lastSeparator == -1 && m_filePath.length() >= 2 && m_filePath.at(1) == QLatin1Char(':'))
+ return m_filePath.mid(2, length - 2);
+#endif
return m_filePath.mid(m_lastSeparator + 1, length);
}
QString QFileSystemEntry::completeBaseName() const
{
findFileNameSeparators();
-#if defined(Q_OS_WIN) || defined(Q_OS_SYMBIAN)
- if (m_lastSeparator == -1 && m_filePath.length() >= 2 && m_filePath.at(1) == QLatin1Char(':'))
- return m_filePath.mid(2);
-#endif
int length = -1;
if (m_firstDotInFileName >= 0) {
length = m_firstDotInFileName + m_lastDotInFileName;
if (m_lastSeparator != -1) // avoid off by one
length--;
}
+#if defined(Q_OS_WIN)
+ if (m_lastSeparator == -1 && m_filePath.length() >= 2 && m_filePath.at(1) == QLatin1Char(':'))
+ return m_filePath.mid(2, length - 2);
+#endif
return m_filePath.mid(m_lastSeparator + 1, length);
}
diff --git a/tests/auto/qfileinfo/tst_qfileinfo.cpp b/tests/auto/qfileinfo/tst_qfileinfo.cpp
index 0c81ba2..5d65d1a 100644
--- a/tests/auto/qfileinfo/tst_qfileinfo.cpp
+++ b/tests/auto/qfileinfo/tst_qfileinfo.cpp
@@ -483,6 +483,8 @@ void tst_QFileInfo::absolutePath_data()
// see task 102898
QTest::newRow("c:\\autoexec.bat") << "c:\\autoexec.bat" << "C:/"
<< "autoexec.bat";
+ QTest::newRow("c:autoexec.bat") << QDir::currentPath().left(2) + "autoexec.bat" << QDir::currentPath()
+ << "autoexec.bat";
#endif
QTest::newRow("QTBUG-19995.1") << drivePrefix + "/System/Library/StartupItems/../Frameworks"
<< drivePrefix + "/System/Library"
@@ -523,6 +525,7 @@ void tst_QFileInfo::absFilePath_data()
QString nonCurrentDrivePrefix =
drivePrefix.left(1).compare("X", Qt::CaseInsensitive) == 0 ? QString("Y:") : QString("X:");
+ QTest::newRow("absFilePathWithoutSlash") << drivePrefix + "tmp.txt" << QDir::currentPath() + "/tmp.txt";
QTest::newRow("<current drive>:my.dll") << drivePrefix + "temp/my.dll" << QDir::currentPath() + "/temp/my.dll";
QTest::newRow("<not current drive>:my.dll") << nonCurrentDrivePrefix + "temp/my.dll"
<< nonCurrentDrivePrefix + "/temp/my.dll";
@@ -668,6 +671,7 @@ void tst_QFileInfo::fileName_data()
QTest::newRow("relativeFileInSubDir") << "temp/tmp.txt" << "tmp.txt";
#if (defined(Q_OS_WIN) && !defined(Q_OS_WINCE)) || defined(Q_OS_SYMBIAN)
QTest::newRow("absFilePath") << "c:\\home\\andy\\tmp.txt" << "tmp.txt";
+ QTest::newRow("driveWithNoSlash") << "c:tmp.txt" << "tmp.txt";
#else
QTest::newRow("absFilePath") << "/home/andy/tmp.txt" << "tmp.txt";
#endif
@@ -724,6 +728,10 @@ void tst_QFileInfo::dir_data()
QTest::newRow("absFilePath") << QDir::currentPath() + "/tmp.txt" << false << QDir::currentPath();
QTest::newRow("absFilePathAbsPath") << QDir::currentPath() + "/tmp.txt" << true << QDir::currentPath();
QTest::newRow("resource1") << ":/tst_qfileinfo/resources/file1.ext1" << true << ":/tst_qfileinfo/resources";
+#ifdef Q_OS_WIN
+ QTest::newRow("driveWithSlash") << "C:/file1.ext1.ext2" << true << "C:/";
+ QTest::newRow("driveWithoutSlash") << QDir::currentPath().left(2) + "file1.ext1.ext2" << false << QDir::currentPath();
+#endif
}
void tst_QFileInfo::dir()
@@ -771,6 +779,10 @@ void tst_QFileInfo::suffix_data()
QTest::newRow("hidden2") << ".ex.ext2" << "ext2";
QTest::newRow("hidden2") << ".e.ext2" << "ext2";
QTest::newRow("hidden2") << "..ext2" << "ext2";
+#ifdef Q_OS_WIN
+ QTest::newRow("driveWithSlash") << "c:/file1.ext1.ext2" << "ext2";
+ QTest::newRow("driveWithoutSlash") << "c:file1.ext1.ext2" << "ext2";
+#endif
}
void tst_QFileInfo::suffix()
@@ -796,6 +808,10 @@ void tst_QFileInfo::completeSuffix_data()
QTest::newRow("data3") << "/path/file.tar" << "tar";
QTest::newRow("resource1") << ":/tst_qfileinfo/resources/file1.ext1" << "ext1";
QTest::newRow("resource2") << ":/tst_qfileinfo/resources/file1.ext1.ext2" << "ext1.ext2";
+#ifdef Q_OS_WIN
+ QTest::newRow("driveWithSlash") << "c:/file1.ext1.ext2" << "ext1.ext2";
+ QTest::newRow("driveWithoutSlash") << "c:file1.ext1.ext2" << "ext1.ext2";
+#endif
}
void tst_QFileInfo::completeSuffix()
@@ -819,6 +835,10 @@ void tst_QFileInfo::baseName_data()
QTest::newRow("data4") << "/path/file" << "file";
QTest::newRow("resource1") << ":/tst_qfileinfo/resources/file1.ext1" << "file1";
QTest::newRow("resource2") << ":/tst_qfileinfo/resources/file1.ext1.ext2" << "file1";
+#ifdef Q_OS_WIN
+ QTest::newRow("driveWithSlash") << "c:/file1.ext1.ext2" << "file1";
+ QTest::newRow("driveWithoutSlash") << "c:file1.ext1.ext2" << "file1";
+#endif
}
void tst_QFileInfo::baseName()
@@ -842,6 +862,10 @@ void tst_QFileInfo::completeBaseName_data()
QTest::newRow("data4") << "/path/file" << "file";
QTest::newRow("resource1") << ":/tst_qfileinfo/resources/file1.ext1" << "file1";
QTest::newRow("resource2") << ":/tst_qfileinfo/resources/file1.ext1.ext2" << "file1.ext1";
+#ifdef Q_OS_WIN
+ QTest::newRow("driveWithSlash") << "c:/file1.ext1.ext2" << "file1.ext1";
+ QTest::newRow("driveWithoutSlash") << "c:file1.ext1.ext2" << "file1.ext1";
+#endif
}
void tst_QFileInfo::completeBaseName()
@@ -1717,7 +1741,7 @@ void tst_QFileInfo::owner()
dwPrefMaxLen, &dwEntriesRead, &dwTotalEntries);
// Check if the current user is a member of Administrators group
if (nStatus == NERR_Success && pBuf){
- for (int i = 0; i < dwEntriesRead; i++) {
+ for (int i = 0; i < (int)dwEntriesRead; i++) {
QString groupName = QString::fromWCharArray(pBuf[i].lgrui0_name);
if (!groupName.compare(QLatin1String("Administrators")))
userName = groupName;