From 257dfa6b3f7043745593c616236eea5c0c32fcb6 Mon Sep 17 00:00:00 2001 From: John Preston Date: Sat, 5 May 2018 21:54:54 +0300 Subject: [PATCH] Improve phone rules checking. --- Telegram/SourceFiles/intro/introphone.cpp | 1 + Telegram/SourceFiles/mtproto/special_config_request.cpp | 7 +++++-- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/Telegram/SourceFiles/intro/introphone.cpp b/Telegram/SourceFiles/intro/introphone.cpp index ed29913aa6..2cf89553db 100644 --- a/Telegram/SourceFiles/intro/introphone.cpp +++ b/Telegram/SourceFiles/intro/introphone.cpp @@ -148,6 +148,7 @@ void PhoneWidget::submit() { _checkRequest->start(1000); _sentPhone = fullNumber(); + Messenger::Instance().mtp()->setUserPhone(_sentPhone); _sentRequest = MTP::send(MTPauth_CheckPhone(MTP_string(_sentPhone)), rpcDone(&PhoneWidget::phoneCheckDone), rpcFail(&PhoneWidget::phoneSubmitFail)); } diff --git a/Telegram/SourceFiles/mtproto/special_config_request.cpp b/Telegram/SourceFiles/mtproto/special_config_request.cpp index 439a91cc32..1faf7b72be 100644 --- a/Telegram/SourceFiles/mtproto/special_config_request.cpp +++ b/Telegram/SourceFiles/mtproto/special_config_request.cpp @@ -33,13 +33,16 @@ constexpr auto kUserAgent = "Mozilla/5.0 (Windows NT 10.0; Win64; x64) " "AppleWebKit/537.36 (KHTML, like Gecko) Chrome/66.0.3359.117 Safari/537.36"; bool CheckPhoneByPrefixesRules(const QString &phone, const QString &rules) { + const auto check = QString(phone).replace( + QRegularExpression("[^0-9]"), + QString()); auto result = false; for (const auto &prefix : rules.split(',')) { if (prefix.isEmpty()) { result = true; - } else if (prefix[0] == '+' && phone.startsWith(prefix.mid(1))) { + } else if (prefix[0] == '+' && check.startsWith(prefix.mid(1))) { result = true; - } else if (prefix[0] == '-' && phone.startsWith(prefix.mid(1))) { + } else if (prefix[0] == '-' && check.startsWith(prefix.mid(1))) { return false; } }