From 5c0cc8a9473e29fec511e8834e4a63da55804fd6 Mon Sep 17 00:00:00 2001 From: John Preston Date: Fri, 18 May 2018 20:03:31 +0300 Subject: [PATCH] Append param to query or hash of callback_url. --- Telegram/Resources/langs/lang.strings | 1 + Telegram/SourceFiles/base/qthelp_url.cpp | 17 ++++++++--------- Telegram/SourceFiles/base/qthelp_url.h | 2 +- .../passport/passport_form_controller.cpp | 2 +- .../passport/passport_panel_controller.cpp | 2 +- 5 files changed, 12 insertions(+), 12 deletions(-) diff --git a/Telegram/Resources/langs/lang.strings b/Telegram/Resources/langs/lang.strings index 1723b33724..47a12e9ceb 100644 --- a/Telegram/Resources/langs/lang.strings +++ b/Telegram/Resources/langs/lang.strings @@ -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 diff --git a/Telegram/SourceFiles/base/qthelp_url.cpp b/Telegram/SourceFiles/base/qthelp_url.cpp index 820ee5de33..d7a741eaf1 100644 --- a/Telegram/SourceFiles/base/qthelp_url.cpp +++ b/Telegram/SourceFiles/base/qthelp_url.cpp @@ -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 diff --git a/Telegram/SourceFiles/base/qthelp_url.h b/Telegram/SourceFiles/base/qthelp_url.h index 4a32406c68..7f8e156cb0 100644 --- a/Telegram/SourceFiles/base/qthelp_url.h +++ b/Telegram/SourceFiles/base/qthelp_url.h @@ -26,7 +26,7 @@ QMap url_parse_params( const QString ¶ms, 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); diff --git a/Telegram/SourceFiles/passport/passport_form_controller.cpp b/Telegram/SourceFiles/passport/passport_form_controller.cpp index b3dec4d135..da2502153b 100644 --- a/Telegram/SourceFiles/passport/passport_form_controller.cpp +++ b/Telegram/SourceFiles/passport/passport_form_controller.cpp @@ -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" diff --git a/Telegram/SourceFiles/passport/passport_panel_controller.cpp b/Telegram/SourceFiles/passport/passport_panel_controller.cpp index 4c5191a180..72a2bc3c59 100644 --- a/Telegram/SourceFiles/passport/passport_panel_controller.cpp +++ b/Telegram/SourceFiles/passport/passport_panel_controller.cpp @@ -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; };