From 75f8b11fb2a4ad2d0d9ecbb2b3bfd98039eb838b Mon Sep 17 00:00:00 2001 From: Leon Zhang Date: Mon, 22 Apr 2019 18:58:25 +0800 Subject: [PATCH] add list range check --- advisor/heuristic.go | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) diff --git a/advisor/heuristic.go b/advisor/heuristic.go index 243fa05..d8377aa 100644 --- a/advisor/heuristic.go +++ b/advisor/heuristic.go @@ -2149,14 +2149,16 @@ func (q *Query4Audit) RuleSpaceWithQuote() Rule { var rule = q.RuleOK() for _, tk := range ast.Tokenize(q.Query) { if tk.Type == ast.TokenTypeQuote { - // 序列化的Val是带引号,所以要取第2个最倒数第二个,这样也就不用担心len<2了。 - switch tk.Val[1] { - case ' ': - rule = HeuristicRules["ARG.009"] - } - switch tk.Val[len(tk.Val)-2] { - case ' ': - rule = HeuristicRules["ARG.009"] + if len(tk.Val) >= 2 { + // 序列化的Val是带引号,所以要取第2个和倒数第二个,这样也就不用担心len<2了。 + switch tk.Val[1] { + case ' ': + rule = HeuristicRules["ARG.009"] + } + switch tk.Val[len(tk.Val)-2] { + case ' ': + rule = HeuristicRules["ARG.009"] + } } } } -- GitLab