提交 cd17cced 编写于 作者: martianzhang's avatar martianzhang

fix #229

  SELECT c1, c2, c3, FROM tb WHERE id < 1000 AND content="mytest* as test"
上级 f818c326
......@@ -64,9 +64,11 @@ func (q *Query4Audit) RuleImplicitAlias() Rule {
// RuleStarAlias ALI.002
func (q *Query4Audit) RuleStarAlias() Rule {
var rule = q.RuleOK()
re := regexp.MustCompile(`(?i)(\*\s+as\b)`)
if re.FindString(q.Query) != "" {
rule = HeuristicRules["ALI.002"]
tkns := ast.Tokenizer(q.Query)
for i, tkn := range tkns {
if tkn.Val == "*" && i+1 < len(tkns) && tkns[i+1].Val == "as" {
rule = HeuristicRules["ALI.002"]
}
}
return rule
}
......
......@@ -60,16 +60,30 @@ func TestRuleImplicitAlias(t *testing.T) {
// ALI.002
func TestRuleStarAlias(t *testing.T) {
common.Log.Debug("Entering function: %s", common.GetFunctionName())
sqls := []string{
"select tbl.* as c1,c2,c3 from tbl where id < 1000",
sqls := [][]string{
{
"select tbl.* AS c1,c2,c3 from tbl where id < 1000",
"SELECT * as",
},
{
`SELECT c1, c2, c3, FROM tb WHERE id < 1000 AND content="mytest* as test"`,
`select *`,
},
}
for _, sql := range sqls {
for _, sql := range sqls[0] {
q, _ := NewQuery4Audit(sql)
rule := q.RuleStarAlias()
if rule.Item != "ALI.002" {
t.Error("Rule not match:", rule.Item, "Expect : ALI.002")
}
}
for _, sql := range sqls[1] {
q, _ := NewQuery4Audit(sql)
rule := q.RuleStarAlias()
if rule.Item != "OK" {
t.Error("Rule not match:", rule.Item, "Expect : OK")
}
}
common.Log.Debug("Exiting function: %s", common.GetFunctionName())
}
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册