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>
This commit is contained in:
Assam Boudjelthia 2023-08-11 01:42:35 +03:00
parent efc4bf5e63
commit ea75e34d69

View File

@ -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));