Skip to content

Commit

Permalink
[carddav] Perform percent encodings and decodings on filenames as nec…
Browse files Browse the repository at this point in the history
…essary. Fixes MER#1186

Filenames received from the server need to be percent-decoded, and
filenames uploaded to the server needed to be percent-encoded.
  • Loading branch information
Bea Lam committed Jul 24, 2015
1 parent ce6534b commit 544a503
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 6 deletions.
8 changes: 4 additions & 4 deletions src/replyparser.cpp
Expand Up @@ -258,7 +258,7 @@ QList<ReplyParser::AddressBookInformation> ReplyParser::parseAddressbookInformat
Q_FOREACH (const QVariant &rv, responses) {
QVariantMap rmap = rv.toMap();
ReplyParser::AddressBookInformation currInfo;
currInfo.url = rmap.value("href").toMap().value("@text").toString();
currInfo.url = QUrl::fromPercentEncoding(rmap.value("href").toMap().value("@text").toString().toUtf8());
currInfo.ctag = rmap.value("propstat").toMap().value("prop").toMap().value("getctag").toMap().value("@text").toString();
currInfo.syncToken = rmap.value("propstat").toMap().value("prop").toMap().value("sync-token").toMap().value("@text").toString();
currInfo.displayName = rmap.value("propstat").toMap().value("prop").toMap().value("displayname").toMap().value("@text").toString();
Expand Down Expand Up @@ -344,7 +344,7 @@ QList<ReplyParser::ContactInformation> ReplyParser::parseSyncTokenDelta(const QB
Q_FOREACH (const QVariant &rv, responses) {
QVariantMap rmap = rv.toMap();
ReplyParser::ContactInformation currInfo;
currInfo.uri = rmap.value("href").toMap().value("@text").toString();
currInfo.uri = QUrl::fromPercentEncoding(rmap.value("href").toMap().value("@text").toString().toUtf8());
currInfo.etag = rmap.value("propstat").toMap().value("prop").toMap().value("getetag").toMap().value("@text").toString();
QMap<QString, QString>::const_iterator it = q->m_contactUris.constBegin();
for ( ; it != q->m_contactUris.constEnd(); ++it) {
Expand Down Expand Up @@ -420,7 +420,7 @@ QList<ReplyParser::ContactInformation> ReplyParser::parseContactMetadata(const Q
Q_FOREACH (const QVariant &rv, responses) {
QVariantMap rmap = rv.toMap();
ReplyParser::ContactInformation currInfo;
currInfo.uri = rmap.value("href").toMap().value("@text").toString();
currInfo.uri = QUrl::fromPercentEncoding(rmap.value("href").toMap().value("@text").toString().toUtf8());
currInfo.etag = rmap.value("propstat").toMap().value("prop").toMap().value("getetag").toMap().value("@text").toString();
QString status = rmap.value("propstat").toMap().value("status").toMap().value("@text").toString();
if (!currInfo.uri.endsWith(QStringLiteral(".vcf"), Qt::CaseInsensitive)) {
Expand Down Expand Up @@ -533,7 +533,7 @@ QMap<QString, ReplyParser::FullContactInformation> ReplyParser::parseContactData
QMap<QString, ReplyParser::FullContactInformation> uriToContactData;
Q_FOREACH (const QVariant &rv, responses) {
QVariantMap rmap = rv.toMap();
QString uri = rmap.value("href").toMap().value("@text").toString();
QString uri = QUrl::fromPercentEncoding(rmap.value("href").toMap().value("@text").toString().toUtf8());
QString etag = rmap.value("propstat").toMap().value("prop").toMap().value("getetag").toMap().value("@text").toString();
QString vcard = rmap.value("propstat").toMap().value("prop").toMap().value("address-data").toMap().value("@text").toString();

Expand Down
11 changes: 9 additions & 2 deletions src/requestgenerator.cpp
Expand Up @@ -337,10 +337,17 @@ QNetworkReply *RequestGenerator::contactMultiget(const QString &serverUrl, const
QString uriHrefs;
Q_FOREACH (const QString &uri, contactUris) {
// note: uriHref is of form: <d:href>/addressbooks/johndoe/contacts/acme-12345.vcf</d:href> etc.
QString href = uri.toHtmlEscaped();
int lastPathMarker = href.lastIndexOf('/');
if (lastPathMarker > 0) {
// percent-encode the filename
QString vcfName = QUrl::toPercentEncoding(href.mid(lastPathMarker + 1));
href = href.mid(0, lastPathMarker+1) + vcfName;
}
if (uri.endsWith(QStringLiteral(".vcf")) && uri.startsWith(addressbookPath)) {
uriHrefs.append(QStringLiteral("<d:href>%1</d:href>").arg(uri.toHtmlEscaped()));
uriHrefs.append(QStringLiteral("<d:href>%1</d:href>").arg(href));
} else {
uriHrefs.append(QStringLiteral("<d:href>%1/%2.vcf</d:href>").arg(addressbookPath).arg(uri.toHtmlEscaped()));
uriHrefs.append(QStringLiteral("<d:href>%1/%2.vcf</d:href>").arg(addressbookPath).arg(href));
}
}

Expand Down

0 comments on commit 544a503

Please sign in to comment.