diff options
author | Kitsune Ral <Kitsune-Ral@users.sf.net> | 2020-04-14 14:21:26 +0200 |
---|---|---|
committer | Kitsune Ral <Kitsune-Ral@users.sf.net> | 2020-04-14 14:21:26 +0200 |
commit | 4088ab4572c5b7cde603aeb1a89bc4515833beaf (patch) | |
tree | a558f40218ab061088ba0a0321375e1ce7161ce1 /lib | |
parent | 58dfe74390ebdd8ec6611d3b8fecfe7d051ff955 (diff) | |
download | libquotient-4088ab4572c5b7cde603aeb1a89bc4515833beaf.tar.gz libquotient-4088ab4572c5b7cde603aeb1a89bc4515833beaf.zip |
BaseJob::makeRequestUrl(): even more tolerance to slash separators
The code is really defensive now, making sure there's exactly one slash
between the base path and the endpoint. It's still very conservative
about the path composition otherwise (no normalisation etc.).
Diffstat (limited to 'lib')
-rw-r--r-- | lib/connection.cpp | 2 | ||||
-rw-r--r-- | lib/jobs/basejob.cpp | 7 | ||||
-rw-r--r-- | lib/jobs/basejob.h | 6 |
3 files changed, 9 insertions, 6 deletions
diff --git a/lib/connection.cpp b/lib/connection.cpp index 1c63adeb..41ecee67 100644 --- a/lib/connection.cpp +++ b/lib/connection.cpp @@ -280,7 +280,7 @@ void Connection::resolveServer(const QString& mxid) return; } qCInfo(MAIN) << ".well-known URL for" << maybeBaseUrl.host() - << "is" << baseUrl.authority(); + << "is" << baseUrl.toString(); setHomeserver(baseUrl); } else { qCInfo(MAIN) << "No .well-known file, using" << maybeBaseUrl diff --git a/lib/jobs/basejob.cpp b/lib/jobs/basejob.cpp index 7cddc343..8e1a63aa 100644 --- a/lib/jobs/basejob.cpp +++ b/lib/jobs/basejob.cpp @@ -212,8 +212,11 @@ QUrl BaseJob::makeRequestUrl(QUrl baseUrl, const QString& path, const QUrlQuery& query) { auto pathBase = baseUrl.path(); - if (!pathBase.endsWith('/') && !path.startsWith('/')) - pathBase.push_back('/'); + // QUrl::adjusted(QUrl::StripTrailingSlashes) doesn't help with root '/' + while (pathBase.endsWith('/')) + pathBase.chop(1); + if (!path.startsWith('/')) // Normally API files do start with '/' + pathBase.push_back('/'); // so this shouldn't be needed these days baseUrl.setPath(pathBase + path, QUrl::TolerantMode); baseUrl.setQuery(query); diff --git a/lib/jobs/basejob.h b/lib/jobs/basejob.h index c8046e9e..2049f59c 100644 --- a/lib/jobs/basejob.h +++ b/lib/jobs/basejob.h @@ -308,9 +308,9 @@ protected: void setExpectedContentTypes(const QByteArrayList& contentTypes); /** Construct a URL out of baseUrl, path and query - * The function automatically adds '/' between baseUrl's path and - * \p path if necessary. The query component of \p baseUrl - * is ignored. + * + * The function ensures exactly one '/' between the path component of + * \p baseUrl and \p path. The query component of \p baseUrl is ignored. */ static QUrl makeRequestUrl(QUrl baseUrl, const QString& path, const QUrlQuery& query = {}); |