From 9744abaada6b106e13976738e8f721a7366872d2 Mon Sep 17 00:00:00 2001 From: wenshao Date: Mon, 3 Jun 2013 14:10:43 +0800 Subject: [PATCH] bug fixed for concat --- .../sql/visitor/SQLEvalVisitorUtils.java | 4 ++ .../druid/sql/visitor/functions/Concat.java | 2 +- .../bvt/filter/wall/MySqlWallTest_concat.java | 39 +++++++++++++++++++ 3 files changed, 44 insertions(+), 1 deletion(-) create mode 100644 src/test/java/com/alibaba/druid/bvt/filter/wall/MySqlWallTest_concat.java diff --git a/src/main/java/com/alibaba/druid/sql/visitor/SQLEvalVisitorUtils.java b/src/main/java/com/alibaba/druid/sql/visitor/SQLEvalVisitorUtils.java index c17eeaffe6..ea3922c745 100644 --- a/src/main/java/com/alibaba/druid/sql/visitor/SQLEvalVisitorUtils.java +++ b/src/main/java/com/alibaba/druid/sql/visitor/SQLEvalVisitorUtils.java @@ -791,6 +791,10 @@ public class SQLEvalVisitorUtils { if (wallConditionContext != null) { wallConditionContext.setConstArithmetic(true); } + + if (leftValue == null || rightValue == null) { + return false; + } Object value = null; switch (x.getOperator()) { diff --git a/src/main/java/com/alibaba/druid/sql/visitor/functions/Concat.java b/src/main/java/com/alibaba/druid/sql/visitor/functions/Concat.java index 57aa04f7e7..43a805b216 100644 --- a/src/main/java/com/alibaba/druid/sql/visitor/functions/Concat.java +++ b/src/main/java/com/alibaba/druid/sql/visitor/functions/Concat.java @@ -33,7 +33,7 @@ public class Concat implements Function { Object itemValue = item.getAttributes().get(EVAL_VALUE); if (itemValue == null) { - continue; + return null; } buf.append(itemValue.toString()); } diff --git a/src/test/java/com/alibaba/druid/bvt/filter/wall/MySqlWallTest_concat.java b/src/test/java/com/alibaba/druid/bvt/filter/wall/MySqlWallTest_concat.java new file mode 100644 index 0000000000..350186435e --- /dev/null +++ b/src/test/java/com/alibaba/druid/bvt/filter/wall/MySqlWallTest_concat.java @@ -0,0 +1,39 @@ +/* + * Copyright 1999-2011 Alibaba Group Holding Ltd. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package com.alibaba.druid.bvt.filter.wall; + +import junit.framework.TestCase; + +import org.junit.Assert; + +import com.alibaba.druid.wall.WallProvider; +import com.alibaba.druid.wall.spi.MySqlWallProvider; + +public class MySqlWallTest_concat extends TestCase { + + public void test_true() throws Exception { + WallProvider provider = new MySqlWallProvider(); + + provider.getConfig().setSelectHavingAlwayTrueCheck(true); + + Assert.assertTrue(provider.checkValid(// + "select * from tb_product_word where name='' or CONCAT(name,style)='' or CONCAT(shop,style)='' or CONCAT(ename,style)=''")); + + Assert.assertEquals(1, provider.getTableStats().size()); + Assert.assertTrue(provider.getTableStats().containsKey("tb_product_word")); + } + +}