Commit 534c90e9 authored by Nicolas Fella's avatar Nicolas Fella
Browse files

Make (own|next)cloud url handling more resilient

Align the two so they are both resilient agains missing https and trailing slashes

BUG: 425807
parent 9f6bd248
/*
SPDX-FileCopyrightText: 2020 Nicolas Fella <nicolas.fella@gmx.de>
SPDX-License-Identifier: GPL-2.0-or-later
*/
#pragma once
#include <QUrl>
QUrl createStatusUrl(const QString &input)
{
QString fixedUrl;
if (!input.startsWith(QLatin1String("http://")) && !input.startsWith(QLatin1String("https://"))) {
fixedUrl.append("https://");
fixedUrl.append(input);
} else {
fixedUrl = input;
}
QUrl url(fixedUrl);
if (!url.path().endsWith(QLatin1Char('/'))) {
url.setPath(url.path() + '/');
}
url.setPath(url.path() + "status.php");
return url;
}
......@@ -15,6 +15,8 @@
#include <QJsonObject>
#include <QDesktopServices>
#include "../cloudurls.h"
// Document for login flow : https://docs.nextcloud.com/server/stable/developer_manual/client_apis/LoginFlow/index.html
void NextcloudUrlIntercepter::interceptRequest(QWebEngineUrlRequestInfo &info)
......@@ -42,21 +44,8 @@ void NextcloudController::checkServer(const QString &path)
Q_EMIT errorMessageChanged();
m_json.clear();
QString urlString = path;
//To remove "/'s" from the end
while(urlString.endsWith("/")) {
urlString.remove(urlString.length() - 1, 1);
}
QUrl url = QUrl::fromUserInput(urlString);
url.setPath(url.path() + '/' + "status.php");
if (url.host().isEmpty()) {
return;
}
checkServer(url);
checkServer(createStatusUrl(path));
}
//To check if url is correct
......
......@@ -15,6 +15,8 @@
#include <QJsonObject>
#include <QDebug>
#include "../cloudurls.h"
OwncloudController::OwncloudController(QObject *parent)
: QObject(parent),
m_errorMessage(QString()),
......@@ -34,25 +36,7 @@ void OwncloudController::checkServer(const QString &username, const QString &pas
m_username = username;
m_password = password;
QString fixedUrl;
if (!path.startsWith(QLatin1String("http://")) && !path.startsWith(QLatin1String("https://"))) {
fixedUrl.append("https://");
fixedUrl.append(path);
} else {
fixedUrl = path;
}
m_json.clear();
QUrl url(fixedUrl);
url = url.adjusted(QUrl::StripTrailingSlash);
url.setPath(url.path() + '/' + "status.php");
if (url.host().isEmpty()) {
return;
}
checkServer(url);
checkServer(createStatusUrl(path));
}
void OwncloudController::checkServer(const QUrl &url)
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment