From 369a29b8240cd3532dcd78e2f1b23b607e294494 Mon Sep 17 00:00:00 2001 From: ZhuangYumin Date: Wed, 20 Dec 2023 07:26:21 +0000 Subject: [PATCH] =?UTF-8?q?=E5=9C=A8=E6=9C=8D=E5=8A=A1=E7=AB=AF=E6=B7=BB?= =?UTF-8?q?=E5=8A=A0=E4=BA=86=E5=8E=9F=E5=A7=8B=E8=AF=B7=E6=B1=82=E7=A7=8D?= =?UTF-8?q?=E7=B1=BB=E6=A0=A1=E9=AA=8C=EF=BC=8C=E5=B9=B6=E4=BF=AE=E6=94=B9?= =?UTF-8?q?=E4=BA=86=E5=90=8E=E7=AB=AF=E5=AF=B9=E6=B5=AE=E7=82=B9=E6=95=B0?= =?UTF-8?q?=E7=9A=84=E6=A0=A1=E9=AA=8C=E8=A7=84=E5=88=99?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- backend/src/lexer.cpp | 10 +++++++--- frontend/Web/index.js | 6 ++++++ 2 files changed, 13 insertions(+), 3 deletions(-) diff --git a/backend/src/lexer.cpp b/backend/src/lexer.cpp index 8681a23..0acdbd7 100644 --- a/backend/src/lexer.cpp +++ b/backend/src/lexer.cpp @@ -336,7 +336,7 @@ bool CommandModifyLexer(const std::string &command, std::string &ISBN, std::string &name, std::string &author, std::string &keyword, double &price) { static std::basic_regex main_pattern( - R"(^ *modify(?: +-ISBN=(?:[!-~]{1,20})| +-name=\"(?:[!#-~]{1,60})\"| +-author=\"(?:[!#-~]{1,60})\"| +-keyword=\"((?:[!#-{}~]{1,60}\|)*(?:[!#-{}~]{1,60}))\"| +-price=[0-9]{1,10}(?:\.[0-9]+)?)+ *$)", + R"(^ *modify(?: +-ISBN=(?:[!-~]{1,20})| +-name=\"(?:[!#-~]{1,60})\"| +-author=\"(?:[!#-~]{1,60})\"| +-keyword=\"((?:[!#-{}~]{1,60}\|)*(?:[!#-{}~]{1,60}))\"| +-price=[0-9]{1,13}(?:\.[0-9]+)?)+ *$)", std::regex_constants::optimize); if (std::regex_match(command, main_pattern)) { std::stringstream ss(command); @@ -373,6 +373,7 @@ bool CommandModifyLexer(const std::string &command, std::string &ISBN, if (keyword.length() > 60) return false; } else if (token[1] == 'p') { if (has_price) return false; + if (token.substr(7).length() > 13) return false; has_price = true; price = std::stod(token.substr(7)); } else @@ -400,7 +401,7 @@ bool CommandModifyLexer(const std::string &command, std::string &ISBN, bool CommandImportLexer(const std::string &command, int &quantity, double &total_cost) { static std::basic_regex main_pattern( - R"(^ *import +[0-9]{1,10} +[0-9]{1,10}(?:\.[0-9]+)? *$)", + R"(^ *import +[0-9]{1,10} +[0-9]{1,13}(?:\.[0-9]+)? *$)", std::regex_constants::optimize); if (std::regex_match(command, main_pattern)) { std::stringstream ss(command); @@ -412,7 +413,10 @@ bool CommandImportLexer(const std::string &command, int &quantity, ss >> quantity_tmp; if (quantity_tmp > 2147483647) return false; quantity = quantity_tmp; - ss >> total_cost; + std::string total_cost_tmp; + ss >> total_cost_tmp; + if(total_cost_tmp.length() > 13) return false; + total_cost = std::stod(total_cost_tmp); return true; } else return false; diff --git a/frontend/Web/index.js b/frontend/Web/index.js index 4415771..8c77ba3 100644 --- a/frontend/Web/index.js +++ b/frontend/Web/index.js @@ -165,6 +165,12 @@ io.on('connection', async (socket) => { socket.emit('response', ret); } else{ + if(head[1]!='S'&&head[1]!='C'&&head[1]!='W'&&head[1]!='R') + { + console.log("input has invalid head"); + socket.emit('response', "Invalid Input"); + return; + } if(substrings.length!=4) { console.log("input has "+substrings.length+" words");