mirror of https://github.com/procxx/kepka.git
parent
ae272074b9
commit
90f4187ca9
|
@ -8,6 +8,23 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
|
||||||
#include "base/qthelp_url.h"
|
#include "base/qthelp_url.h"
|
||||||
|
|
||||||
namespace qthelp {
|
namespace qthelp {
|
||||||
|
namespace {
|
||||||
|
|
||||||
|
QRegularExpression RegExpProtocol() {
|
||||||
|
static const auto result = QRegularExpression("^([a-zA-Z]+)://");
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool IsGoodProtocol(const QString &protocol) {
|
||||||
|
const auto equals = [&](QLatin1String string) {
|
||||||
|
return protocol.compare(string, Qt::CaseInsensitive) == 0;
|
||||||
|
};
|
||||||
|
return equals(qstr("http"))
|
||||||
|
|| equals(qstr("https"))
|
||||||
|
|| equals(qstr("tg"));
|
||||||
|
}
|
||||||
|
|
||||||
|
} // namespace
|
||||||
|
|
||||||
QMap<QString, QString> url_parse_params(
|
QMap<QString, QString> url_parse_params(
|
||||||
const QString ¶ms,
|
const QString ¶ms,
|
||||||
|
@ -55,4 +72,24 @@ QString url_append_query_or_hash(const QString &url, const QString &add) {
|
||||||
+ add;
|
+ add;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
QString validate_url(const QString &value) {
|
||||||
|
const auto trimmed = value.trimmed();
|
||||||
|
if (trimmed.isEmpty()) {
|
||||||
|
return QString();
|
||||||
|
}
|
||||||
|
const auto match = TextUtilities::RegExpDomainExplicit().match(trimmed);
|
||||||
|
if (!match.hasMatch()) {
|
||||||
|
const auto domain = TextUtilities::RegExpDomain().match(trimmed);
|
||||||
|
if (!domain.hasMatch() || domain.capturedStart() != 0) {
|
||||||
|
return QString();
|
||||||
|
}
|
||||||
|
return qstr("http://") + trimmed;
|
||||||
|
} else if (match.capturedStart() != 0) {
|
||||||
|
return QString();
|
||||||
|
}
|
||||||
|
const auto protocolMatch = RegExpProtocol().match(trimmed);
|
||||||
|
Assert(protocolMatch.hasMatch());
|
||||||
|
return IsGoodProtocol(protocolMatch.captured(1)) ? trimmed : QString();
|
||||||
|
}
|
||||||
|
|
||||||
} // namespace qthelp
|
} // namespace qthelp
|
||||||
|
|
|
@ -30,4 +30,6 @@ QString url_append_query_or_hash(const QString &url, const QString &add);
|
||||||
|
|
||||||
bool is_ipv6(const QString &ip);
|
bool is_ipv6(const QString &ip);
|
||||||
|
|
||||||
|
QString validate_url(const QString &value);
|
||||||
|
|
||||||
} // namespace qthelp
|
} // namespace qthelp
|
||||||
|
|
|
@ -9,6 +9,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
|
||||||
|
|
||||||
#include "history/history_widget.h"
|
#include "history/history_widget.h"
|
||||||
#include "base/qthelp_regex.h"
|
#include "base/qthelp_regex.h"
|
||||||
|
#include "base/qthelp_url.h"
|
||||||
#include "boxes/abstract_box.h"
|
#include "boxes/abstract_box.h"
|
||||||
#include "ui/wrap/vertical_layout.h"
|
#include "ui/wrap/vertical_layout.h"
|
||||||
#include "window/window_controller.h"
|
#include "window/window_controller.h"
|
||||||
|
@ -72,40 +73,6 @@ private:
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
QRegularExpression RegExpProtocol() {
|
|
||||||
static const auto result = QRegularExpression("^([a-zA-Z]+)://");
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
|
|
||||||
bool IsGoodProtocol(const QString &protocol) {
|
|
||||||
const auto equals = [&](QLatin1String string) {
|
|
||||||
return protocol.compare(string, Qt::CaseInsensitive) == 0;
|
|
||||||
};
|
|
||||||
return equals(qstr("http"))
|
|
||||||
|| equals(qstr("https"))
|
|
||||||
|| equals(qstr("tg"));
|
|
||||||
}
|
|
||||||
|
|
||||||
QString NormalizeUrl(const QString &value) {
|
|
||||||
const auto trimmed = value.trimmed();
|
|
||||||
if (trimmed.isEmpty()) {
|
|
||||||
return QString();
|
|
||||||
}
|
|
||||||
const auto match = TextUtilities::RegExpDomainExplicit().match(trimmed);
|
|
||||||
if (!match.hasMatch()) {
|
|
||||||
const auto domain = TextUtilities::RegExpDomain().match(trimmed);
|
|
||||||
if (!domain.hasMatch() || domain.capturedStart() != 0) {
|
|
||||||
return QString();
|
|
||||||
}
|
|
||||||
return qstr("http://") + trimmed;
|
|
||||||
} else if (match.capturedStart() != 0) {
|
|
||||||
return QString();
|
|
||||||
}
|
|
||||||
const auto protocolMatch = RegExpProtocol().match(trimmed);
|
|
||||||
Assert(protocolMatch.hasMatch());
|
|
||||||
return IsGoodProtocol(protocolMatch.captured(1)) ? trimmed : QString();
|
|
||||||
}
|
|
||||||
|
|
||||||
//bool ValidateUrl(const QString &value) {
|
//bool ValidateUrl(const QString &value) {
|
||||||
// const auto match = TextUtilities::RegExpDomain().match(value);
|
// const auto match = TextUtilities::RegExpDomain().match(value);
|
||||||
// if (!match.hasMatch() || match.capturedStart() != 0) {
|
// if (!match.hasMatch() || match.capturedStart() != 0) {
|
||||||
|
@ -156,7 +123,7 @@ void EditLinkBox::prepare() {
|
||||||
|
|
||||||
const auto submit = [=] {
|
const auto submit = [=] {
|
||||||
const auto linkText = text->getLastText();
|
const auto linkText = text->getLastText();
|
||||||
const auto linkUrl = NormalizeUrl(url->getLastText());
|
const auto linkUrl = qthelp::validate_url(url->getLastText());
|
||||||
if (linkText.isEmpty()) {
|
if (linkText.isEmpty()) {
|
||||||
text->showError();
|
text->showError();
|
||||||
return;
|
return;
|
||||||
|
|
|
@ -188,6 +188,13 @@ QString SpecialScanCredentialsKey(SpecialFile type) {
|
||||||
Unexpected("Type in SpecialScanCredentialsKey.");
|
Unexpected("Type in SpecialScanCredentialsKey.");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
QString ValidateUrl(const QString &url) {
|
||||||
|
const auto result = qthelp::validate_url(url);
|
||||||
|
return result.startsWith("tg://", Qt::CaseInsensitive)
|
||||||
|
? QString()
|
||||||
|
: result;
|
||||||
|
}
|
||||||
|
|
||||||
} // namespace
|
} // namespace
|
||||||
|
|
||||||
FormRequest::FormRequest(
|
FormRequest::FormRequest(
|
||||||
|
@ -199,7 +206,7 @@ FormRequest::FormRequest(
|
||||||
const QString &errors)
|
const QString &errors)
|
||||||
: botId(botId)
|
: botId(botId)
|
||||||
, scope(scope)
|
, scope(scope)
|
||||||
, callbackUrl(callbackUrl)
|
, callbackUrl(ValidateUrl(callbackUrl))
|
||||||
, publicKey(publicKey)
|
, publicKey(publicKey)
|
||||||
, payload(payload)
|
, payload(payload)
|
||||||
, errors(errors) {
|
, errors(errors) {
|
||||||
|
|
Loading…
Reference in New Issue