From 8f5279dd9fc420ab55592f9a952daaccb5a5f17e Mon Sep 17 00:00:00 2001 From: ZhuangYumin Date: Thu, 14 Dec 2023 06:40:48 +0000 Subject: [PATCH] =?UTF-8?q?=E7=BB=99exit=E5=92=8Cquit=E6=B7=BB=E5=8A=A0?= =?UTF-8?q?=E6=A0=A1=E9=AA=8C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- backend/src/engine.cpp | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/backend/src/engine.cpp b/backend/src/engine.cpp index 2c803ff..1745531 100644 --- a/backend/src/engine.cpp +++ b/backend/src/engine.cpp @@ -46,6 +46,10 @@ std::vector BookStoreEngineClass::Execute( std::string head = ""; ss >> head; if (head == "quit" || head == "exit") { + static std::basic_regex quit_regex(R"(^ *(quit|exit) *$)", + std::regex_constants::optimize); + if (!std::regex_match(cmd, quit_regex)) + return std::vector({"Invalid"}); while (login_stack.size()) { login_count[login_stack.top().first]--; login_stack.pop(); @@ -394,9 +398,9 @@ std::vector BookStoreEngineClass::ExecuteShowFinance( std::vector BookStoreEngineClass::ExecuteLog( const std::string &cmd, std::stack> &login_stack) { - static std::basic_regex log_regex( - R"(^ *log *$)", std::regex_constants::optimize); - if(!std::regex_match(cmd, log_regex)) + static std::basic_regex log_regex(R"(^ *log *$)", + std::regex_constants::optimize); + if (!std::regex_match(cmd, log_regex)) return std::vector({"Invalid"}); return std::vector(); }