diff options
author | Qt Forward Merge Bot <qt_forward_merge_bot@qt-project.org> | 2019-07-17 01:00:27 +0200 |
---|---|---|
committer | Edward Welbourne <edward.welbourne@qt.io> | 2019-07-17 10:44:21 +0200 |
commit | 64df0eda36fea91b71783b23bfdf733b6983c250 (patch) | |
tree | 92cbd069b534a873a33a46c7735592eaca78d9cd /src/corelib | |
parent | 8b34296e6a86ce5ad9dba6ac54c84a64cec09b96 (diff) | |
parent | a837ec15fec100567730a7bedb06655ef891ac96 (diff) |
Merge remote-tracking branch 'origin/5.13' into dev
Conflicts:
src/corelib/global/qlogging.cpp
src/gui/painting/qtextureglyphcache_p.h
src/gui/text/qfontengine.cpp
src/widgets/widgets/qlineedit.cpp
Change-Id: Ic8798538df466b7141caa8bbf1fb7605eb56be37
Diffstat (limited to 'src/corelib')
-rw-r--r-- | src/corelib/io/qfilesystemiterator_unix.cpp | 47 | ||||
-rw-r--r-- | src/corelib/io/qsavefile.cpp | 1 | ||||
-rw-r--r-- | src/corelib/text/qbytearray.cpp | 7 |
3 files changed, 48 insertions, 7 deletions
diff --git a/src/corelib/io/qfilesystemiterator_unix.cpp b/src/corelib/io/qfilesystemiterator_unix.cpp index 5ac7e13a2e..2d09c277eb 100644 --- a/src/corelib/io/qfilesystemiterator_unix.cpp +++ b/src/corelib/io/qfilesystemiterator_unix.cpp @@ -40,13 +40,54 @@ #include "qplatformdefs.h" #include "qfilesystemiterator_p.h" +#if QT_CONFIG(textcodec) +# include <qtextcodec.h> +# include <private/qutfcodec_p.h> +#endif + #ifndef QT_NO_FILESYSTEMITERATOR +#include <memory> + #include <stdlib.h> #include <errno.h> QT_BEGIN_NAMESPACE +static bool checkNameDecodable(const char *d_name, qsizetype len) +{ + // This function is called in a loop from advance() below, but the loop is + // usually run only once. + +#if QT_CONFIG(textcodec) + // We identify the codecs by their RFC 2978 MIBenum values. In this + // function: + // 3 US-ASCII (ANSI X3.4-1986) + // 4 Latin1 (ISO-8859-1) + // 106 UTF-8 + QTextCodec *codec = QTextCodec::codecForLocale(); +# ifdef QT_LOCALE_IS_UTF8 + int mibEnum = 106; +# else + int mibEnum = codec->mibEnum(); +# endif + if (Q_LIKELY(mibEnum == 106)) // UTF-8 + return QUtf8::isValidUtf8(d_name, len).isValidUtf8; + if (mibEnum == 3) // US-ASCII + return QtPrivate::isAscii(QLatin1String(d_name, len)); + if (mibEnum == 4) // Latin 1 + return true; + + // fall back to generic QTextCodec + QTextCodec::ConverterState cs(QTextCodec::IgnoreHeader); + codec->toUnicode(d_name, len, &cs); + return cs.invalidChars == 0 && cs.remainingChars == 0; +#else + // if we have no text codecs, then QString::fromLocal8Bit is fromLatin1 + return true; +#endif +} + QFileSystemIterator::QFileSystemIterator(const QFileSystemEntry &entry, QDir::Filters filters, const QStringList &nameFilters, QDirIterator::IteratorFlags flags) : nativePath(entry.nativeFilePath()) @@ -81,9 +122,9 @@ bool QFileSystemIterator::advance(QFileSystemEntry &fileEntry, QFileSystemMetaDa dirEntry = QT_READDIR(dir); 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()); + qsizetype len = strlen(dirEntry->d_name); + if (checkNameDecodable(dirEntry->d_name, len)) { + fileEntry = QFileSystemEntry(nativePath + QByteArray(dirEntry->d_name, len), QFileSystemEntry::FromNativePath()); metaData.fillFromDirEnt(*dirEntry); return true; } diff --git a/src/corelib/io/qsavefile.cpp b/src/corelib/io/qsavefile.cpp index 915d0a0a00..04f440fea2 100644 --- a/src/corelib/io/qsavefile.cpp +++ b/src/corelib/io/qsavefile.cpp @@ -197,6 +197,7 @@ bool QSaveFile::open(OpenMode mode) return false; } unsetError(); + d->writeError = QFileDevice::NoError; if ((mode & (ReadOnly | WriteOnly)) == 0) { qWarning("QSaveFile::open: Open mode not specified"); return false; diff --git a/src/corelib/text/qbytearray.cpp b/src/corelib/text/qbytearray.cpp index fcf7b5e709..c50e087c10 100644 --- a/src/corelib/text/qbytearray.cpp +++ b/src/corelib/text/qbytearray.cpp @@ -972,12 +972,11 @@ QByteArray qUncompress(const uchar* data, int nbytes) \section2 8-bit Character Comparisons In QByteArray, the notion of uppercase and lowercase and of which - character is greater than or less than another character is - locale dependent. This affects functions that support a case + character is greater than or less than another character is done + in the Latin-1 locale. This affects functions that support a case insensitive option or that compare or lowercase or uppercase their arguments. Case insensitive operations and comparisons will - be accurate if both strings contain only ASCII characters. (If \c - $LC_CTYPE is set, most Unix systems do "the right thing".) + be accurate if both strings contain only Latin-1 characters. Functions that this affects include contains(), indexOf(), lastIndexOf(), operator<(), operator<=(), operator>(), operator>=(), isLower(), isUpper(), toLower() and toUpper(). |