diff --git a/src/main/java/com/alibaba/druid/wall/spi/WallVisitorUtils.java b/src/main/java/com/alibaba/druid/wall/spi/WallVisitorUtils.java index c768f2b2ac..5d42d097bd 100644 --- a/src/main/java/com/alibaba/druid/wall/spi/WallVisitorUtils.java +++ b/src/main/java/com/alibaba/druid/wall/spi/WallVisitorUtils.java @@ -1506,8 +1506,7 @@ public class WallVisitorUtils { return; } - if (WallVisitorUtils.queryBlockFromIsNull(visitor, x.getLeft()) - || WallVisitorUtils.queryBlockFromIsNull(visitor, x.getRight())) { + if (WallVisitorUtils.queryBlockFromIsNull(visitor, x.getRight())) { boolean isTopUpdateStatement = false; SQLObject selectParent = x.getParent(); while (selectParent instanceof SQLUnionQuery // diff --git a/src/test/java/com/alibaba/druid/bvt/filter/wall/MustParameterizedTest3.java b/src/test/java/com/alibaba/druid/bvt/filter/wall/MustParameterizedTest3.java index 9dc6f82cc4..406cad11e8 100644 --- a/src/test/java/com/alibaba/druid/bvt/filter/wall/MustParameterizedTest3.java +++ b/src/test/java/com/alibaba/druid/bvt/filter/wall/MustParameterizedTest3.java @@ -38,7 +38,8 @@ public class MustParameterizedTest3 extends TestCase { Assert.assertTrue(WallUtils.isValidateMySql("select * from t where id = ? ORDER BY 1", config)); Assert.assertTrue(WallUtils.isValidateMySql("select 1, 2, 3 from t where id = ?", config)); Assert.assertFalse(WallUtils.isValidateMySql("select 1, 2, 3 from t where id = 7", config)); - Assert.assertFalse(WallUtils.isValidateMySql("select 1, 2, 3 from t where id = ? union select * from t", config)); + Assert.assertTrue(WallUtils.isValidateMySql("select 1, 2, 3 from t where id = ? union select * from t", config)); + Assert.assertFalse(WallUtils.isValidateMySql("select 1, 2, 3 from t where id = ? union select 1, 2, 3", config)); Assert.assertFalse(WallUtils.isValidateMySql("select 1, 2, 3 from t where id = ? union select * from t fid = fid", config)); Assert.assertFalse(WallUtils.isValidateMySql("select 1, 2, 3 from t where id = ? union select * from t fid > 5", config)); } diff --git a/src/test/java/com/alibaba/druid/bvt/filter/wall/OracleWallTest6.java b/src/test/java/com/alibaba/druid/bvt/filter/wall/OracleWallTest6.java new file mode 100644 index 0000000000..521b51eb2c --- /dev/null +++ b/src/test/java/com/alibaba/druid/bvt/filter/wall/OracleWallTest6.java @@ -0,0 +1,66 @@ +/* + * 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.WallUtils; + +public class OracleWallTest6 extends TestCase { + + public void test_true() throws Exception { + String sql = // + "select *" + + " from (SELECT Distinct notice.NSERIAL," + + " unit.CUNIT_name," + + " us.CUSER_name," + + " to_char(notice.DCREATE, 'yyyy-mm-dd') DCREATE," + + " notice.csubject," + + " notice.ccontent" + + " From mewp_notice_info notice, bas_user us, bas_unit unit" + + " Left Join bas_area xsArea" + + " On unit.ccounty_code = xsArea.Carea_Code" + + " Left Join bas_area pqArea" + + " On unit.cpiece_code = pqArea.Carea_Code" + + " Left Join bas_area xzArea" + + " On unit.cctown_code = xzArea.Carea_Code" + + " Left Join bas_area czArea" + + " On unit.cvillage_code = czArea.Carea_Code" + + " Where notice.cunit_code = unit.cunit_code" + + " And notice.cuser_id = us.cuser_code" + + " And notice.nstate = 4" + + " And (notice.nrole = '****' or notice.nrole = '202')" + + " and notice.cunit_code in" + + " (select 'CP0008'" + + " from dual" + + " union" + + " select Distinct t.cunit_code" + + " from bas_unit t, bas_area us" + + " where t.ccounty_code = us.carea_code" + + " and t.ccounty_code = 'CP'" + + " and t.ctype = '201'" + + " union" + + " select Distinct auser.cunit_code" + + " from bas_user auser, bas_user_role ur" + + " where auser.cuser_code = ur.cuser_code" + + " and (ur.nrole_id = '1' or ur.nrole_id = '20'))" + + " order by DCREATE desc)" + + " where rownum <= 30"; + Assert.assertTrue(WallUtils.isValidateOracle(sql)); + } +}