mirror of
https://github.com/alibaba/druid.git
synced 2023-03-04 19:17:16 +00:00
add wall test
This commit is contained in:
@@ -1,9 +1,11 @@
|
||||
package com.alibaba.druid.filter.wall;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.LinkedHashMap;
|
||||
import java.util.List;
|
||||
|
||||
import com.alibaba.druid.sql.ast.SQLStatement;
|
||||
import com.alibaba.druid.sql.parser.NotAllowCommentException;
|
||||
import com.alibaba.druid.sql.parser.SQLStatementParser;
|
||||
import com.alibaba.druid.sql.parser.Token;
|
||||
|
||||
@@ -30,7 +32,7 @@ public abstract class WallProvider {
|
||||
if (whiteList == null) {
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
return whiteList.get(sql) != null;
|
||||
}
|
||||
|
||||
@@ -48,8 +50,19 @@ public abstract class WallProvider {
|
||||
SQLStatementParser parser = createParser(sql);
|
||||
parser.getLexer().setAllowComment(false); // permit comment
|
||||
|
||||
List<SQLStatement> statementList = parser.parseStatementList();
|
||||
if(parser.getLexer().token() != Token.EOF) {
|
||||
List<SQLStatement> statementList = new ArrayList<SQLStatement>();
|
||||
|
||||
try {
|
||||
parser.parseStatementList(statementList);
|
||||
} catch (NotAllowCommentException e) {
|
||||
if (throwException) {
|
||||
throw new WallRuntimeException("not allow comment : " + sql);
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
if (parser.getLexer().token() != Token.EOF) {
|
||||
if (throwException) {
|
||||
throw new WallRuntimeException("illegal statement : " + sql);
|
||||
}
|
||||
|
||||
@@ -5,6 +5,7 @@ import java.util.Map;
|
||||
|
||||
import com.alibaba.druid.sql.parser.Keywords;
|
||||
import com.alibaba.druid.sql.parser.Lexer;
|
||||
import com.alibaba.druid.sql.parser.NotAllowCommentException;
|
||||
import com.alibaba.druid.sql.parser.Token;
|
||||
|
||||
public class HiveLexer extends Lexer {
|
||||
@@ -147,9 +148,17 @@ public class HiveLexer extends Lexer {
|
||||
stringVal = new String(buf, np, sp);
|
||||
token = Token.MULTI_LINE_COMMENT;
|
||||
}
|
||||
|
||||
if (token != Token.HINT && !isAllowComment()) {
|
||||
throw new NotAllowCommentException();
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
if (!isAllowComment()) {
|
||||
throw new NotAllowCommentException();
|
||||
}
|
||||
|
||||
if (ch == '/') {
|
||||
scanChar();
|
||||
|
||||
@@ -7,6 +7,7 @@ import java.util.Map;
|
||||
|
||||
import com.alibaba.druid.sql.parser.Keywords;
|
||||
import com.alibaba.druid.sql.parser.Lexer;
|
||||
import com.alibaba.druid.sql.parser.NotAllowCommentException;
|
||||
import com.alibaba.druid.sql.parser.SQLParseException;
|
||||
import com.alibaba.druid.sql.parser.Token;
|
||||
|
||||
@@ -257,9 +258,17 @@ public class OracleLexer extends Lexer {
|
||||
stringVal = new String(buf, np, sp);
|
||||
token = Token.MULTI_LINE_COMMENT;
|
||||
}
|
||||
|
||||
if (token != Token.HINT && !isAllowComment()) {
|
||||
throw new NotAllowCommentException();
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
if (!isAllowComment()) {
|
||||
throw new NotAllowCommentException();
|
||||
}
|
||||
|
||||
if (ch == '/' || ch == '-') {
|
||||
scanChar();
|
||||
|
||||
Reference in New Issue
Block a user