Append param to query or hash of callback_url.

This commit is contained in:
John Preston 2018-05-18 20:03:31 +03:00
parent 308fb19da4
commit 5c0cc8a947
5 changed files with 12 additions and 12 deletions

View File

@ -1630,6 +1630,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
"lng_passport_error_too_large" = "This file is too large.";
"lng_passport_error_bad_size" = "This image has bad dimensions.";
"lng_passport_error_cant_read" = "Can't read this file. Please choose an image.";
"lng_passport_bad_name" = "Use latin characters only.";
// Wnd specific

View File

@ -44,16 +44,15 @@ bool is_ipv6(const QString &ip) {
return ip.indexOf('.') < 0 && ip.indexOf(':') >= 0;
}
QString url_append_query(const QString &url, const QString &add) {
const auto query = ranges::find(url, '?');
const auto hash = ranges::find(url, '#');
const auto base = url.mid(0, hash - url.begin());
const auto added = base
+ (hash <= query ? '?' : '&')
QString url_append_query_or_hash(const QString &url, const QString &add) {
const auto query = url.lastIndexOf('?');
if (query < 0) {
return url + '?' + add;
}
const auto hash = url.lastIndexOf('#');
return url
+ (query >= 0 && query > url.lastIndexOf('#') ? '&' : '?')
+ add;
const auto result = added
+ (hash < url.end() ? url.mid(hash - url.begin()) : QString());
return result;
}
} // namespace qthelp

View File

@ -26,7 +26,7 @@ QMap<QString, QString> url_parse_params(
const QString &params,
UrlParamNameTransform transform = UrlParamNameTransform::NoTransform);
QString url_append_query(const QString &url, const QString &add);
QString url_append_query_or_hash(const QString &url, const QString &add);
bool is_ipv6(const QString &ip);

View File

@ -2099,7 +2099,7 @@ void FormController::cancelSure() {
if (!_request.callbackUrl.isEmpty()
&& (_serviceErrorText.isEmpty()
|| ForwardServiceErrorRequired(_serviceErrorText))) {
const auto url = qthelp::url_append_query(
const auto url = qthelp::url_append_query_or_hash(
_request.callbackUrl,
(_submitSuccess
? "tg_passport=success"

View File

@ -68,7 +68,7 @@ EditDocumentScheme GetDocumentScheme(
} else if (!QRegularExpression(
"^[a-zA-Z\\- ]+$"
).match(value).hasMatch()) {
return "Use latin characters only.";// lang(lng_passport_bad_name);
return lang(lng_passport_bad_name);
}
return base::none;
};