From f115b031ffcbcf648f1aed4c8dbbb3f83adddb57 Mon Sep 17 00:00:00 2001 From: weideguo <2515717245@qq.com> Date: Sun, 28 Nov 2021 18:52:05 +0800 Subject: [PATCH] =?UTF-8?q?mongodb=E6=9F=A5=E8=AF=A2=E4=BC=98=E5=8C=96=20(?= =?UTF-8?q?hhyo#1252)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- sql/engines/mongo.py | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/sql/engines/mongo.py b/sql/engines/mongo.py index a9a06ef0bd..9de05f890e 100644 --- a/sql/engines/mongo.py +++ b/sql/engines/mongo.py @@ -688,11 +688,13 @@ def filter_sql(self, sql='', limit_num=0): def query_check(self, db_name=None, sql=''): """提交查询前的检查""" + sql = sql.strip() if sql.startswith("explain"): - sql = sql.replace("explain", "") + ".explain()" + sql = sql[7:]+".explain()" + sql = re.sub("[;\s]*.explain\(\)$", ".explain()", sql).strip() result = {'msg': '', 'bad_query': False, 'filtered_sql': sql, 'has_star': False} pattern = re.compile( - r'''^db\.(\w+\.?)+(?:\([\s\S]*\)$)|^db\.getCollection\((?:\s*)(?:'|")(\w+\.?)+('|")(\s*)\)\.([A-Za-z]+)(\([\s\S]*\)$)''') + r'''^db\.(\w+\.?)+(?:\([\s\S]*\)(\s*;*)$)|^db\.getCollection\((?:\s*)(?:'|")(\w+\.?)+('|")(\s*)\)\.([A-Za-z]+)(\([\s\S]*\)(\s*;*)$)''') m = pattern.match(sql) if m is not None: logger.debug(sql)