QDirIterator: Skip inconvertible file names on Unix

In the case when user's local encoding is UTF-8, QDirIterator
may list entries which names can't be correctly converted from
UTF-8 to UTF-16, e.g. for "\xC0\xB0" file name QDirIterator::fileName()
returns "\uFFFD\uFFFD" (FFFD is a code of Replacement Character).
The problem is that you can't do anything with such directory
entries because there is no way to get the original entry names.

List only those names that can be converted to QString
and then back to the local encoding without corruption.

Change-Id: Ib6a71dea8ce9601876040c07276c325fd997e767
Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
bb10
Alexander Volkov 2017-10-30 16:30:50 +03:00 committed by Thiago Macieira
parent c35c017a6c
commit 094869d4a8
1 changed files with 12 additions and 5 deletions

View File

@ -77,12 +77,19 @@ bool QFileSystemIterator::advance(QFileSystemEntry &fileEntry, QFileSystemMetaDa
if (!dir)
return false;
dirEntry = QT_READDIR(dir);
for (;;) {
dirEntry = QT_READDIR(dir);
if (dirEntry) {
fileEntry = QFileSystemEntry(nativePath + QByteArray(dirEntry->d_name), QFileSystemEntry::FromNativePath());
metaData.fillFromDirEnt(*dirEntry);
return true;
if (dirEntry) {
// process entries with correct UTF-8 names only
if (QFile::encodeName(QFile::decodeName(dirEntry->d_name)) == dirEntry->d_name) {
fileEntry = QFileSystemEntry(nativePath + QByteArray(dirEntry->d_name), QFileSystemEntry::FromNativePath());
metaData.fillFromDirEnt(*dirEntry);
return true;
}
} else {
break;
}
}
lastError = errno;