summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAlexander Volkov <a.volkov@rusbitech.ru>2017-10-30 16:30:50 +0300
committerThiago Macieira <thiago.macieira@intel.com>2017-11-14 15:55:06 +0000
commit094869d4a88c3d0187d2f9c03294ce32f3503533 (patch)
treec0b01eca8102e24f70a82bc906afe531f3fb117a
parentc35c017a6c4a9b9b20f18d121300dd96609ee253 (diff)
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>
-rw-r--r--src/corelib/io/qfilesystemiterator_unix.cpp17
1 files changed, 12 insertions, 5 deletions
diff --git a/src/corelib/io/qfilesystemiterator_unix.cpp b/src/corelib/io/qfilesystemiterator_unix.cpp
index 0d1438f137..a9acf542d4 100644
--- a/src/corelib/io/qfilesystemiterator_unix.cpp
+++ b/src/corelib/io/qfilesystemiterator_unix.cpp
@@ -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;