From 4c1e23c9d3053771c88449025ea332ce723ab665 Mon Sep 17 00:00:00 2001 From: Thiago Macieira Date: Wed, 21 Feb 2024 08:31:05 -0800 Subject: [PATCH] QFileSystemIterator/Darwin: enforce NFC encoding in QString MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Amends 83f7125ac866ed5a2aaace56ffc866f21f9730b4. We replaced QFile::decodeName() with QStringDecoder so we'd know whether the decoding from UTF-8 had failed, but forgot about Darwin's enforced normalization. Fixes: QTBUG-122624 Change-Id: I01ec3c774d9943adb903fffd17b5edc54c34c067 Reviewed-by: Ahmad Samir Reviewed-by: Robert Griebl Reviewed-by: Tor Arne Vestbø --- src/corelib/io/qfilesystemiterator_unix.cpp | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/src/corelib/io/qfilesystemiterator_unix.cpp b/src/corelib/io/qfilesystemiterator_unix.cpp index 30b1a005a9..a1130728ef 100644 --- a/src/corelib/io/qfilesystemiterator_unix.cpp +++ b/src/corelib/io/qfilesystemiterator_unix.cpp @@ -38,6 +38,14 @@ QFileSystemIterator::~QFileSystemIterator() = default; bool QFileSystemIterator::advance(QFileSystemEntry &fileEntry, QFileSystemMetaData &metaData) { + auto asFileEntry = [this](QStringView name) { +#ifdef Q_OS_DARWIN + // must match QFile::decodeName + QString normalized = name.toString().normalized(QString::NormalizationForm_C); + name = normalized; +#endif + return QFileSystemEntry(dirPath + name, QFileSystemEntry::FromInternalPath()); + }; if (!dir) return false; @@ -62,7 +70,7 @@ bool QFileSystemIterator::advance(QFileSystemEntry &fileEntry, QFileSystemMetaDa auto *end = toUtf16.appendToBuffer(buffer.data(), name); buffer.resize(end - buffer.constData()); if (!toUtf16.hasError()) { - fileEntry = {dirPath + QStringView(buffer), QFileSystemEntry::FromInternalPath()}; + fileEntry = asFileEntry(buffer); metaData.fillFromDirEnt(*dirEntry); return true; } else {