From 75ab12cb4d52ef8e4729d742bff645b49bfce66e Mon Sep 17 00:00:00 2001 From: Erik Verbruggen Date: Fri, 29 Nov 2024 16:36:01 +0100 Subject: [PATCH] chore: log percent-encoded URL/filename (#11998) This can be used to debug Unicode normalization/encoding issues. --- src/libsync/discovery.cpp | 11 ++++++++++- src/libsync/httplogger.cpp | 2 +- 2 files changed, 11 insertions(+), 2 deletions(-) diff --git a/src/libsync/discovery.cpp b/src/libsync/discovery.cpp index 2953d3a83c3..f96cb363f9b 100644 --- a/src/libsync/discovery.cpp +++ b/src/libsync/discovery.cpp @@ -308,8 +308,15 @@ void ProcessDirectoryJob::processFile(const PathTuple &path, const LocalInfo &localEntry, const RemoteInfo &serverEntry, const SyncJournalFileRecord &dbEntry) { + // The percent-encoded file name as it would be passed in an HTTP request. This can be used to + // debug Unicode encoding/normalization issues. + auto encodedFileName = QUrl::fromLocalFile(path._original).toEncoded().sliced(std::string_view("file:").length()); const char *hasServer = serverEntry.isValid() ? "true" : _queryServer == ParentNotChanged ? "db" : "false"; const char *hasLocal = localEntry.isValid() ? "true" : _queryLocal == ParentNotChanged ? "db" : "false"; + + // The code below is formatted like this ON PURPOSE: each field is db/local/server, one field + // per (source code) line, so it's easy to understand. + // clang-format off qCInfo(lcDisco).nospace() << "Processing " << path._original << " | valid: " << dbEntry.isValid() << "/" << hasLocal << "/" << hasServer << " | mtime: " << dbEntry._modtime << "/" << localEntry.modtime << "/" << serverEntry.modtime @@ -319,7 +326,9 @@ void ProcessDirectoryJob::processFile(const PathTuple &path, << " | perm: " << dbEntry._remotePerm << "//" << serverEntry.remotePerm << " | fileid: " << dbEntry._fileId << "//" << serverEntry.fileId << " | inode: " << dbEntry._inode << "/" << localEntry.inode << "/" - << " | type: " << dbEntry._type << "/" << localEntry.type << "/" << (serverEntry.isDirectory ? ItemTypeDirectory : ItemTypeFile); + << " | type: " << dbEntry._type << "/" << localEntry.type << "/" << (serverEntry.isDirectory ? ItemTypeDirectory : ItemTypeFile) + << " (" << encodedFileName << ")"; + // clang-format on if (_discoveryData->isRenamed(path._original)) { qCDebug(lcDisco) << "Ignoring renamed"; diff --git a/src/libsync/httplogger.cpp b/src/libsync/httplogger.cpp index 059dc90c5a8..d9b36a3f018 100644 --- a/src/libsync/httplogger.cpp +++ b/src/libsync/httplogger.cpp @@ -43,7 +43,7 @@ bool isTextBody(const QString &s) struct HttpContext { HttpContext(const QNetworkRequest &request) - : originalUrl(request.url().toString()) + : originalUrl(QString::fromUtf8(request.url().toEncoded())) // Encoded URL as it is passed "over the wire" , lastUrl(request.url()) , id(QString::fromUtf8(request.rawHeader(QByteArrayLiteral("X-Request-ID")))) {