mirror of
https://github.com/alibaba/druid.git
synced 2023-03-04 19:17:16 +00:00
improve sql wall
This commit is contained in:
@@ -91,6 +91,7 @@ import com.alibaba.druid.sql.visitor.functions.Ucase;
|
||||
import com.alibaba.druid.sql.visitor.functions.Unhex;
|
||||
import com.alibaba.druid.util.HexBin;
|
||||
import com.alibaba.druid.util.JdbcUtils;
|
||||
import com.alibaba.druid.wall.WallContext;
|
||||
import com.alibaba.druid.wall.spi.WallVisitorUtils;
|
||||
import com.alibaba.druid.wall.spi.WallVisitorUtils.WallConditionContext;
|
||||
import com.alibaba.druid.wall.spi.WallVisitorUtils.WallSelectQueryContext;
|
||||
|
||||
@@ -647,9 +647,9 @@ public class WallVisitorUtils {
|
||||
SQLExpr right = x.getRight();
|
||||
Object leftResult = getValue(visitor, left);
|
||||
Object rightResult = getValue(visitor, right);
|
||||
|
||||
|
||||
if (x.getOperator() == SQLBinaryOperator.Like && leftResult instanceof String && leftResult.equals(rightResult)) {
|
||||
addViolation(visitor, ErrorCode.DoubleConstCondition, "same const like", x);
|
||||
addViolation(visitor, ErrorCode.SameConstLike, "same const like", x);
|
||||
}
|
||||
|
||||
if (x.getOperator() == SQLBinaryOperator.Like || x.getOperator() == SQLBinaryOperator.NotLike) {
|
||||
@@ -664,7 +664,16 @@ public class WallVisitorUtils {
|
||||
if (x.getOperator() == SQLBinaryOperator.BooleanAnd) {
|
||||
if (rightResult != null && x.getLeft() instanceof SQLBinaryOpExpr) {
|
||||
SQLBinaryOpExpr leftBinaryOpExpr = (SQLBinaryOpExpr) x.getLeft();
|
||||
if (leftBinaryOpExpr.getOperator() == SQLBinaryOperator.BooleanAnd) {
|
||||
|
||||
if (leftBinaryOpExpr.getOperator() != SQLBinaryOperator.BooleanAnd //
|
||||
&& leftBinaryOpExpr.getOperator() != SQLBinaryOperator.BooleanOr //
|
||||
&& leftResult != null //
|
||||
&& visitor != null) {
|
||||
addViolation(visitor, ErrorCode.DoubleConstCondition, "double const condition", x);
|
||||
}
|
||||
|
||||
if (leftBinaryOpExpr.getOperator() == SQLBinaryOperator.BooleanAnd //
|
||||
|| leftBinaryOpExpr.getOperator() == SQLBinaryOperator.BooleanOr) {
|
||||
Object leftRightVal = getValue(leftBinaryOpExpr.getRight());
|
||||
if (leftRightVal != null) {
|
||||
addViolation(visitor, ErrorCode.DoubleConstCondition, "double const condition", x);
|
||||
|
||||
Reference in New Issue
Block a user