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 <ville.voutilainen@qt.io> (cherry picked from commit ea75e34d6968bb59624874411e793c95b26d0dbe) Reviewed-by: Qt Cherry-pick Bot <cherrypick_bot@qt-project.org>
This commit is contained in:
parent
15ed84677c
commit
9e0850b564
@ -605,7 +605,8 @@ QJniObject parseUri(const QString &uri)
|
|||||||
|
|
||||||
DocumentFilePtr DocumentFile::parseFromAnyUri(const QString &fileName)
|
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))
|
if (DocumentsContract::isDocumentUri(uri))
|
||||||
return fromSingleUri(uri);
|
return fromSingleUri(uri);
|
||||||
@ -613,17 +614,17 @@ DocumentFilePtr DocumentFile::parseFromAnyUri(const QString &fileName)
|
|||||||
const QString documentType = "/document/"_L1;
|
const QString documentType = "/document/"_L1;
|
||||||
const QString treeType = "/tree/"_L1;
|
const QString treeType = "/tree/"_L1;
|
||||||
|
|
||||||
const int treeIndex = fileName.indexOf(treeType);
|
const int treeIndex = encodedUri.indexOf(treeType);
|
||||||
const int documentIndex = fileName.indexOf(documentType);
|
const int documentIndex = encodedUri.indexOf(documentType);
|
||||||
const int index = fileName.lastIndexOf("/");
|
const int index = encodedUri.lastIndexOf(QUrl::toPercentEncoding("/"));
|
||||||
|
|
||||||
if (index <= treeIndex + treeType.size() || index <= documentIndex + documentType.size())
|
if (index <= treeIndex + treeType.size() || index <= documentIndex + documentType.size())
|
||||||
return fromTreeUri(uri);
|
return fromTreeUri(uri);
|
||||||
|
|
||||||
const QString parentUrl = fileName.left(index);
|
const QString parentUrl = encodedUri.left(index);
|
||||||
DocumentFilePtr parentDocFile = fromTreeUri(parseUri(parentUrl));
|
DocumentFilePtr parentDocFile = fromTreeUri(parseUri(parentUrl));
|
||||||
|
|
||||||
const QString baseName = fileName.mid(index);
|
const QString baseName = encodedUri.mid(index);
|
||||||
const QString fileUrl = parentUrl + QUrl::toPercentEncoding(baseName);
|
const QString fileUrl = parentUrl + QUrl::toPercentEncoding(baseName);
|
||||||
|
|
||||||
DocumentFilePtr docFile = std::make_shared<MakeableDocumentFile>(parseUri(fileUrl));
|
DocumentFilePtr docFile = std::make_shared<MakeableDocumentFile>(parseUri(fileUrl));
|
||||||
|
Loading…
x
Reference in New Issue
Block a user