From 9e0850b56462b6f0e93d7b866c1df001c7c3012c Mon Sep 17 00:00:00 2001 From: Assam Boudjelthia Date: Fri, 11 Aug 2023 01:42:35 +0300 Subject: [PATCH] Android: fix content URI handling for non-ascii file names Pass an encoded URI string before parsing them through the Android APIs. Fixes: QTBUG-114435 Change-Id: I65131799fad81bfe7490d663d3b7996c94d37f0b Reviewed-by: Ville Voutilainen (cherry picked from commit ea75e34d6968bb59624874411e793c95b26d0dbe) Reviewed-by: Qt Cherry-pick Bot --- .../platforms/android/androidcontentfileengine.cpp | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/src/plugins/platforms/android/androidcontentfileengine.cpp b/src/plugins/platforms/android/androidcontentfileengine.cpp index c86bbeae776..4b3355c115e 100644 --- a/src/plugins/platforms/android/androidcontentfileengine.cpp +++ b/src/plugins/platforms/android/androidcontentfileengine.cpp @@ -605,7 +605,8 @@ QJniObject parseUri(const QString &uri) DocumentFilePtr DocumentFile::parseFromAnyUri(const QString &fileName) { - const QJniObject uri = parseUri(fileName); + const QString encodedUri = QUrl(fileName).toEncoded(); + const QJniObject uri = parseUri(encodedUri); if (DocumentsContract::isDocumentUri(uri)) return fromSingleUri(uri); @@ -613,17 +614,17 @@ DocumentFilePtr DocumentFile::parseFromAnyUri(const QString &fileName) const QString documentType = "/document/"_L1; const QString treeType = "/tree/"_L1; - const int treeIndex = fileName.indexOf(treeType); - const int documentIndex = fileName.indexOf(documentType); - const int index = fileName.lastIndexOf("/"); + const int treeIndex = encodedUri.indexOf(treeType); + const int documentIndex = encodedUri.indexOf(documentType); + const int index = encodedUri.lastIndexOf(QUrl::toPercentEncoding("/")); if (index <= treeIndex + treeType.size() || index <= documentIndex + documentType.size()) return fromTreeUri(uri); - const QString parentUrl = fileName.left(index); + const QString parentUrl = encodedUri.left(index); DocumentFilePtr parentDocFile = fromTreeUri(parseUri(parentUrl)); - const QString baseName = fileName.mid(index); + const QString baseName = encodedUri.mid(index); const QString fileUrl = parentUrl + QUrl::toPercentEncoding(baseName); DocumentFilePtr docFile = std::make_shared(parseUri(fileUrl));