diff --git a/Telegram/SourceFiles/passport/passport_panel_controller.cpp b/Telegram/SourceFiles/passport/passport_panel_controller.cpp index f6def4ced..4219e9c83 100644 --- a/Telegram/SourceFiles/passport/passport_panel_controller.cpp +++ b/Telegram/SourceFiles/passport/passport_panel_controller.cpp @@ -20,6 +20,14 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL namespace Passport { +constexpr auto kMaxNameSize = 255; +constexpr auto kMaxDocumentSize = 24; +constexpr auto kMaxStreetSize = 64; +constexpr auto kMinCitySize = 2; +constexpr auto kMaxCitySize = 64; +constexpr auto kMinPostcodeSize = 2; +constexpr auto kMaxPostcodeSize = 12; + EditDocumentScheme GetDocumentScheme( Scope::Type type, base::optional scansType) { @@ -39,9 +47,18 @@ EditDocumentScheme GetDocumentScheme( return value; }; const auto DontValidate = nullptr; - const auto NotEmptyValidate = [](const QString &value) { - return !value.isEmpty(); + const auto LimitedValidate = [](int max, int min = 1) { + return [=](const QString &value) { + return (value.size() >= min) && (value.size() <= max); + }; }; + const auto NameValidate = LimitedValidate(kMaxNameSize); + const auto DocumentValidate = LimitedValidate(kMaxDocumentSize); + const auto StreetValidate = LimitedValidate(kMaxStreetSize); + const auto CityValidate = LimitedValidate(kMaxCitySize, kMinCitySize); + const auto PostcodeValidate = LimitedValidate( + kMaxPostcodeSize, + kMinPostcodeSize); const auto DateValidate = [](const QString &value) { return QRegularExpression( "^\\d{2}\\.\\d{2}\\.\\d{4}$" @@ -82,16 +99,18 @@ EditDocumentScheme GetDocumentScheme( PanelDetailsType::Text, qsl("first_name"), lang(lng_passport_first_name), - NotEmptyValidate, + NameValidate, DontFormat, + kMaxNameSize, }, { ValueClass::Fields, PanelDetailsType::Text, qsl("last_name"), lang(lng_passport_last_name), - DontValidate, + NameValidate, DontFormat, + kMaxNameSize, }, { ValueClass::Fields, @@ -122,8 +141,9 @@ EditDocumentScheme GetDocumentScheme( PanelDetailsType::Text, qsl("document_no"), lang(lng_passport_document_number), - NotEmptyValidate, + DocumentValidate, DontFormat, + kMaxDocumentSize, }, { ValueClass::Scans, @@ -161,8 +181,9 @@ EditDocumentScheme GetDocumentScheme( PanelDetailsType::Text, qsl("street_line1"), lang(lng_passport_street), - NotEmptyValidate, + StreetValidate, DontFormat, + kMaxStreetSize, }, { ValueClass::Fields, @@ -171,14 +192,16 @@ EditDocumentScheme GetDocumentScheme( lang(lng_passport_street), DontValidate, DontFormat, + kMaxStreetSize, }, { ValueClass::Fields, PanelDetailsType::Text, qsl("city"), lang(lng_passport_city), - NotEmptyValidate, + CityValidate, DontFormat, + kMaxStreetSize, }, { ValueClass::Fields, @@ -187,6 +210,7 @@ EditDocumentScheme GetDocumentScheme( lang(lng_passport_state), DontValidate, DontFormat, + kMaxStreetSize, }, { ValueClass::Fields, @@ -201,8 +225,9 @@ EditDocumentScheme GetDocumentScheme( PanelDetailsType::Text, qsl("post_code"), lang(lng_passport_postcode), - NotEmptyValidate, + PostcodeValidate, DontFormat, + kMaxPostcodeSize, }, }; return result; diff --git a/Telegram/SourceFiles/passport/passport_panel_details_row.cpp b/Telegram/SourceFiles/passport/passport_panel_details_row.cpp index 7cae5285b..5fc447ec5 100644 --- a/Telegram/SourceFiles/passport/passport_panel_details_row.cpp +++ b/Telegram/SourceFiles/passport/passport_panel_details_row.cpp @@ -24,7 +24,11 @@ namespace { class TextRow : public PanelDetailsRow { public: - TextRow(QWidget *parent, const QString &label, const QString &value); + TextRow( + QWidget *parent, + const QString &label, + const QString &value, + int limit); bool setFocusFast() override; rpl::producer value() const override; @@ -191,10 +195,12 @@ private: TextRow::TextRow( QWidget *parent, const QString &label, - const QString &value) + const QString &value, + int limit) : PanelDetailsRow(parent, label) , _field(this, st::passportDetailsField, nullptr, value) , _value(value) { + _field->setMaxLength(limit); connect(_field, &Ui::InputField::changed, [=] { _value = valueCurrent(); }); @@ -890,11 +896,12 @@ object_ptr PanelDetailsRow::Create( not_null controller, const QString &label, const QString &value, - const QString &error) { + const QString &error, + int limit) { auto result = [&]() -> object_ptr { switch (type) { case Type::Text: - return object_ptr(parent, label, value); + return object_ptr(parent, label, value, limit); case Type::Country: return object_ptr(parent, controller, label, value); case Type::Gender: diff --git a/Telegram/SourceFiles/passport/passport_panel_details_row.h b/Telegram/SourceFiles/passport/passport_panel_details_row.h index b6216b693..47fb6010b 100644 --- a/Telegram/SourceFiles/passport/passport_panel_details_row.h +++ b/Telegram/SourceFiles/passport/passport_panel_details_row.h @@ -59,7 +59,8 @@ public: not_null controller, const QString &label, const QString &value, - const QString &error); + const QString &error, + int limit = 0); virtual bool setFocusFast(); virtual rpl::producer value() const = 0; diff --git a/Telegram/SourceFiles/passport/passport_panel_edit_document.cpp b/Telegram/SourceFiles/passport/passport_panel_edit_document.cpp index 990d3c094..f24aee12a 100644 --- a/Telegram/SourceFiles/passport/passport_panel_edit_document.cpp +++ b/Telegram/SourceFiles/passport/passport_panel_edit_document.cpp @@ -246,7 +246,8 @@ not_null PanelEditDocument::setupContent( _controller, row.label, valueOrEmpty(*fields, row.key), - QString()))); + QString(), + row.lengthLimit))); } inner->add( diff --git a/Telegram/SourceFiles/passport/passport_panel_edit_document.h b/Telegram/SourceFiles/passport/passport_panel_edit_document.h index 693db926d..e4dfde999 100644 --- a/Telegram/SourceFiles/passport/passport_panel_edit_document.h +++ b/Telegram/SourceFiles/passport/passport_panel_edit_document.h @@ -38,6 +38,7 @@ struct EditDocumentScheme { QString label; base::lambda validate; base::lambda format; + int lengthLimit = 0; }; std::vector rows; QString rowsHeader;