给exit和quit添加校验
This commit is contained in:
@ -46,6 +46,10 @@ std::vector<std::string> BookStoreEngineClass::Execute(
|
||||
std::string head = "";
|
||||
ss >> head;
|
||||
if (head == "quit" || head == "exit") {
|
||||
static std::basic_regex<char> quit_regex(R"(^ *(quit|exit) *$)",
|
||||
std::regex_constants::optimize);
|
||||
if (!std::regex_match(cmd, quit_regex))
|
||||
return std::vector<std::string>({"Invalid"});
|
||||
while (login_stack.size()) {
|
||||
login_count[login_stack.top().first]--;
|
||||
login_stack.pop();
|
||||
@ -394,9 +398,9 @@ std::vector<std::string> BookStoreEngineClass::ExecuteShowFinance(
|
||||
std::vector<std::string> BookStoreEngineClass::ExecuteLog(
|
||||
const std::string &cmd,
|
||||
std::stack<std::pair<std::string, int>> &login_stack) {
|
||||
static std::basic_regex<char> log_regex(
|
||||
R"(^ *log *$)", std::regex_constants::optimize);
|
||||
if(!std::regex_match(cmd, log_regex))
|
||||
static std::basic_regex<char> log_regex(R"(^ *log *$)",
|
||||
std::regex_constants::optimize);
|
||||
if (!std::regex_match(cmd, log_regex))
|
||||
return std::vector<std::string>({"Invalid"});
|
||||
return std::vector<std::string>();
|
||||
}
|
||||
|
Reference in New Issue
Block a user