diff options
author | Assam Boudjelthia <assam.boudjelthia@qt.io> | 2023-08-11 01:42:35 +0300 |
---|---|---|
committer | Assam Boudjelthia <assam.boudjelthia@qt.io> | 2023-08-15 15:23:30 +0300 |
commit | ea75e34d6968bb59624874411e793c95b26d0dbe (patch) | |
tree | fee7ab9249dbb122db373c8be2fbf6743751e61d /src/plugins/platforms/android | |
parent | efc4bf5e63cd90c2e1f3bda1cce8dea957865f0c (diff) |
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
Pick-to: 6.6 6.5 6.2 5.15
Change-Id: I65131799fad81bfe7490d663d3b7996c94d37f0b
Reviewed-by: Ville Voutilainen <ville.voutilainen@qt.io>
Diffstat (limited to 'src/plugins/platforms/android')
-rw-r--r-- | src/plugins/platforms/android/androidcontentfileengine.cpp | 13 |
1 files changed, 7 insertions, 6 deletions
diff --git a/src/plugins/platforms/android/androidcontentfileengine.cpp b/src/plugins/platforms/android/androidcontentfileengine.cpp index c86bbeae77..4b3355c115 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<MakeableDocumentFile>(parseUri(fileUrl)); |