improve sql wall

This commit is contained in:
yakolee
2014-03-26 19:15:17 +08:00
parent c971aec5ba
commit b5eda0cf2e
3 changed files with 57 additions and 6 deletions
@@ -110,7 +110,7 @@ public class MySqlLexer extends Lexer {
return;
}
if (!isAllowComment()) {
if (!isAllowComment() && (isEOF() || !isSafeComment(stringVal))) {
throw new NotAllowCommentException();
}
}
@@ -446,7 +446,7 @@ public class MySqlLexer extends Lexer {
return;
}
if (!isAllowComment()) {
if (!isAllowComment() && (isEOF() || !isSafeComment(stringVal))) {
throw new NotAllowCommentException();
}
@@ -486,11 +486,38 @@ public class MySqlLexer extends Lexer {
return;
}
if (!isAllowComment()) {
if (!isAllowComment() && (isEOF() || !isSafeComment(stringVal))) {
throw new NotAllowCommentException();
}
return;
}
}
private boolean isSafeComment(String comment) {
if (comment == null) {
return true;
}
comment = comment.toLowerCase();
if (comment.indexOf("select") != -1 //
|| comment.indexOf("delete") != -1 //
|| comment.indexOf("insert") != -1 //
|| comment.indexOf("update") != -1 //
|| comment.indexOf("into") != -1 //
|| comment.indexOf("where") != -1 //
|| comment.indexOf("or") != -1 //
|| comment.indexOf("and") != -1 //
|| comment.indexOf("union") != -1 //
|| comment.indexOf('\'') != -1 //
|| comment.indexOf('=') != -1 //
|| comment.indexOf('>') != -1 //
|| comment.indexOf('<') != -1 //
|| comment.indexOf('&') != -1 //
|| comment.indexOf('|') != -1 //
|| comment.indexOf('^') != -1 //
) {
return false;
}
return true;
}
}