From 9483d17fc8a236bc051baa5ce913b0be7f2c7b25 Mon Sep 17 00:00:00 2001 From: John Preston Date: Thu, 7 Mar 2024 21:24:32 +0400 Subject: [PATCH] Validate quick reply name. --- .../business/settings_quick_replies.cpp | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) diff --git a/Telegram/SourceFiles/settings/business/settings_quick_replies.cpp b/Telegram/SourceFiles/settings/business/settings_quick_replies.cpp index cc55987cb..97b0c9a61 100644 --- a/Telegram/SourceFiles/settings/business/settings_quick_replies.cpp +++ b/Telegram/SourceFiles/settings/business/settings_quick_replies.cpp @@ -162,6 +162,22 @@ void QuickReplies::setupContent( Ui::ResizeFitChild(this, content); } +[[nodiscard]] bool ValidShortcutName(const QString &name) { + if (name.isEmpty() || name.size() > 32) { + return false; + } + for (const auto &ch : name) { + if (!ch.isLetterOrNumber() + && (ch != '_') + && (ch != 0x200c) + && (ch != 0x00b7) + && (ch < 0x0d80 || ch > 0x0dff)) { + return false; + } + } + return true; +} + } // namespace Type QuickRepliesId() { @@ -195,7 +211,7 @@ void EditShortcutNameBox( const auto callback = [=] { const auto name = field->getLastText().trimmed(); - if (name.isEmpty()) { + if (!ValidShortcutName(name)) { field->showError(); } else { submit(name, [weak = Ui::MakeWeak(box)] {