Normalize realpath(3) output to composed form

All strings coming out of POSIX API calls are converted to composed form
by QFile::decodeName. Do the same for realpath(3) output. This is
especially important for HFS+, which will store file names in decomposed
form, and APIs will therefore return strings in decomposed form.

Task-number: QTBUG-55896
Change-Id: I5e51f4e5712ff26bf9644cbcf9a9603995748892
Reviewed-by: Morten Johan Sørvig <morten.sorvig@qt.io>
This commit is contained in:
Erik Verbruggen 2016-10-06 11:24:38 +02:00
parent 557abfc327
commit 49d3bb0058
2 changed files with 14 additions and 1 deletions

View File

@ -276,7 +276,7 @@ QFileSystemEntry QFileSystemEngine::canonicalName(const QFileSystemEntry &entry,
if (ret) {
data.knownFlagsMask |= QFileSystemMetaData::ExistsAttribute;
data.entryFlags |= QFileSystemMetaData::ExistsAttribute;
QString canonicalPath = QDir::cleanPath(QString::fromLocal8Bit(ret));
QString canonicalPath = QDir::cleanPath(QFile::decodeName(ret));
free(ret);
return QFileSystemEntry(canonicalPath);
} else if (errno == ENOENT) { // file doesn't exist

View File

@ -770,6 +770,19 @@ void tst_QFileInfo::canonicalFilePath()
QDir::current().rmdir(linkTarget);
}
#endif
#ifdef Q_OS_DARWIN
{
// Check if canonicalFilePath's result is in Composed normalization form.
QString path = QString::fromLatin1("caf\xe9");
QDir dir(QDir::tempPath());
dir.mkdir(path);
QString canonical = QFileInfo(dir.filePath(path)).canonicalFilePath();
QString roundtrip = QFile::decodeName(QFile::encodeName(canonical));
QCOMPARE(canonical, roundtrip);
dir.rmdir(path);
}
#endif
}
void tst_QFileInfo::fileName_data()