mirror of
https://github.com/alibaba/druid.git
synced 2023-03-04 19:17:16 +00:00
WallConfig support strictSyntaxCheck
This commit is contained in:
@@ -22,7 +22,6 @@ import com.alibaba.druid.sql.dialect.sqlserver.ast.SQLServerTop;
|
||||
import com.alibaba.druid.sql.dialect.sqlserver.ast.expr.SQLServerObjectReferenceExpr;
|
||||
import com.alibaba.druid.sql.parser.Lexer;
|
||||
import com.alibaba.druid.sql.parser.SQLExprParser;
|
||||
import com.alibaba.druid.sql.parser.SQLSelectParser;
|
||||
import com.alibaba.druid.sql.parser.Token;
|
||||
|
||||
public class SQLServerExprParser extends SQLExprParser {
|
||||
|
||||
@@ -50,6 +50,7 @@ public class WallConfig implements WallConfigMBean {
|
||||
private boolean truncateAllow = false;
|
||||
|
||||
private boolean commentAllow = false;
|
||||
private boolean strictSyntaxCheck = true;
|
||||
|
||||
private boolean describeAllow = false;
|
||||
|
||||
@@ -357,6 +358,14 @@ public class WallConfig implements WallConfigMBean {
|
||||
this.commentAllow = commentAllow;
|
||||
}
|
||||
|
||||
public boolean isStrictSyntaxCheck() {
|
||||
return strictSyntaxCheck;
|
||||
}
|
||||
|
||||
public void setStrictSyntaxCheck(boolean strictSyntaxCheck) {
|
||||
this.strictSyntaxCheck = strictSyntaxCheck;
|
||||
}
|
||||
|
||||
public Set<String> getDenyFunctions() {
|
||||
return denyFunctions;
|
||||
}
|
||||
|
||||
@@ -260,6 +260,11 @@ public abstract class WallProvider {
|
||||
result.getViolations().add(new SyntaxErrorViolation(e, sql));
|
||||
incrementCommentDeniedCount();
|
||||
return result;
|
||||
} catch (ParserException e) {
|
||||
if (config.isStrictSyntaxCheck()) {
|
||||
result.getViolations().add(new SyntaxErrorViolation(e, sql));
|
||||
}
|
||||
return result;
|
||||
} catch (Exception e) {
|
||||
result.getViolations().add(new SyntaxErrorViolation(e, sql));
|
||||
return result;
|
||||
|
||||
@@ -0,0 +1,23 @@
|
||||
package com.alibaba.druid.bvt.filter.wall;
|
||||
|
||||
import junit.framework.TestCase;
|
||||
|
||||
import org.junit.Assert;
|
||||
|
||||
import com.alibaba.druid.wall.WallConfig;
|
||||
import com.alibaba.druid.wall.WallUtils;
|
||||
|
||||
public class StrictSyntaxCheckTest extends TestCase {
|
||||
|
||||
public void test_syntax() throws Exception {
|
||||
Assert.assertFalse(WallUtils.isValidateMySql(//
|
||||
"SELECT SELECT")); // 部分永真
|
||||
}
|
||||
|
||||
public void test_syntax_1() throws Exception {
|
||||
WallConfig config = new WallConfig();
|
||||
config.setStrictSyntaxCheck(false);
|
||||
Assert.assertTrue(WallUtils.isValidateMySql(//
|
||||
"SELECT SELECT", config)); // 部分永真
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user