@@ -129,6 +129,20 @@ public abstract class AbstractSQLConfig implements SQLConfig {
129129
130130
131131 RAW_MAP = new LinkedHashMap <>(); // 保证顺序,避免配置冲突等意外情况
132+
133+ RAW_MAP .put ("+" , "" );
134+ RAW_MAP .put ("-" , "" );
135+ RAW_MAP .put ("*" , "" );
136+ RAW_MAP .put ("/" , "" );
137+ RAW_MAP .put ("=" , "" );
138+ RAW_MAP .put ("!=" , "" );
139+ RAW_MAP .put (">" , "" );
140+ RAW_MAP .put (">=" , "" );
141+ RAW_MAP .put ("<" , "" );
142+ RAW_MAP .put ("<=" , "" );
143+ RAW_MAP .put ("%" , "" );
144+ RAW_MAP .put ("(" , "" );
145+ RAW_MAP .put (")" , "" );
132146
133147 // MySQL 关键字
134148 RAW_MAP .put ("AS" , "" );
@@ -141,6 +155,11 @@ public abstract class AbstractSQLConfig implements SQLConfig {
141155 RAW_MAP .put ("NOT" , "" );
142156 RAW_MAP .put ("VALUE" , "" );
143157 RAW_MAP .put ("DISTINCT" , "" );
158+ RAW_MAP .put ("CASE" , "" );
159+ RAW_MAP .put ("WHEN" , "" );
160+ RAW_MAP .put ("THEN" , "" );
161+ RAW_MAP .put ("ELSE" , "" );
162+ RAW_MAP .put ("END" , "" );
144163
145164 //时间
146165 RAW_MAP .put ("now()" , "" );
@@ -1705,7 +1724,7 @@ private String[] parseArgsSplitWithComma(String param, boolean isColumn, boolean
17051724 if (ck .startsWith ("`" ) && ck .endsWith ("`" )) {
17061725 origin = ck .substring (1 , ck .length () - 1 );
17071726 //sql 注入判断 判断
1708- if (StringUtil .isName (origin ) == false ) {
1727+ if (origin . startsWith ( "_" ) || StringUtil .isName (origin ) == false ) {
17091728 throw new IllegalArgumentException ("字符 " + ck + " 不合法!"
17101729 + "预编译模式下 @column:\" `column0`,`column1`:alias;function0(arg0,arg1,...);function1(...):alias...\" "
17111730 + " 中所有字符串 column 都必须必须为1个单词 !" );
@@ -1720,12 +1739,6 @@ else if (ck.startsWith("'") && ck.endsWith("'")) {
17201739 + "预编译模式下 @column:\" column0,column1:alias;function0(arg0,arg1,...);function1(...):alias...\" "
17211740 + " 中字符串参数不合法,必须以 ' 开头, ' 结尾,字符串中不能包含 ' " );
17221741 }
1723- //sql 注入判断 判断
1724- if (origin .contains ("--" ) || PATTERN_STRING .matcher (origin ).matches () == true ) {
1725- throw new IllegalArgumentException ("字符 " + ck + " 不合法!"
1726- + "预编译模式下 @column:\" column0,column1:alias;function0(arg0,arg1,...);function1(...):alias...\" "
1727- + " 中所有字符串 arg 都必须不符合正则表达式 " + PATTERN_STRING + " 且不包含连续减号 -- !" );
1728- }
17291742
17301743 // 1.字符串不是字段也没有别名,所以不解析别名 2. 是字符串,进行预编译,使用getValue() ,对字符串进行截取
17311744 ckeys [i ] = getValue (origin ).toString ();
@@ -1745,7 +1758,7 @@ else if (ck.startsWith("'") && ck.endsWith("'")) {
17451758 + "关键字必须全大写,且以空格分隔的参数,空格必须只有 1 个!其它情况不允许空格!" );
17461759 }
17471760 } else {
1748- if (origin .startsWith ("_" ) || origin .contains ("--" ) || PATTERN_FUNCTION .matcher (origin ).matches () == false ) {
1761+ if (origin .startsWith ("_" ) || origin .contains ("--" )) { // || PATTERN_FUNCTION.matcher(origin).matches() == false) {
17491762 throw new IllegalArgumentException ("字符 " + ck + " 不合法!"
17501763 + "预编译模式下 @column:\" column0,column1:alias;function0(arg0,arg1,...);function1(...):alias...\" "
17511764 + " 中所有 arg 都必须是1个不以 _ 开头的单词 或者符合正则表达式 " + PATTERN_FUNCTION + " 且不包含连续减号 -- !DISTINCT 必须全大写,且后面必须有且只有 1 个空格!其它情况不允许空格!" );
@@ -1818,12 +1831,35 @@ private String praseArgsSplitWithSpace(String mkes[]) {
18181831 }
18191832
18201833 //这里为什么还要做一次判断 是因为解析窗口函数调用的时候会判断一次
1821- if (isPrepared ()) {
1822- if (origin .startsWith ("_" ) || origin .contains ("--" ) || PATTERN_FUNCTION .matcher (origin ).matches () == false ) {
1823- throw new IllegalArgumentException ("字符 " + origin + " 不合法!"
1834+ String ck = origin ;
1835+ // 如果参数包含 "`" 或 "'" ,解析字符串
1836+ if (ck .startsWith ("`" ) && ck .endsWith ("`" )) {
1837+ origin = ck .substring (1 , ck .length () - 1 );
1838+ if (origin .startsWith ("_" ) || StringUtil .isName (origin ) == false ) {
1839+ throw new IllegalArgumentException ("字符 " + ck + " 不合法!"
1840+ + "预编译模式下 @column:\" `column0`,`column1`:alias;function0(arg0,arg1,...);function1(...):alias...\" "
1841+ + " 中所有字符串 column 都必须必须为1个单词 !" );
1842+ }
1843+
1844+ mkes [j ] = getKey (origin ).toString ();
1845+ continue ;
1846+ }
1847+ else if (ck .startsWith ("'" ) && ck .endsWith ("'" )) {
1848+ origin = ck .substring (1 , ck .length () - 1 );
1849+ if (origin .contains ("'" )) {
1850+ throw new IllegalArgumentException ("字符串 " + ck + " 不合法!"
18241851 + "预编译模式下 @column:\" column0,column1:alias;function0(arg0,arg1,...);function1(...):alias...\" "
1825- + " 中所有 arg 都必须是1个不以 _ 开头的单词 或者符合正则表达式 " + PATTERN_FUNCTION + " 且不包含连续减号 -- !DISTINCT 必须全大写,且后面必须有且只有 1 个空格!其它情况不允许空格! " );
1852+ + " 中字符串参数不合法,必须以 ' 开头, ' 结尾,字符串中不能包含 ' " );
18261853 }
1854+
1855+ // 1.字符串不是字段也没有别名,所以不解析别名 2. 是字符串,进行预编译,使用getValue() ,对字符串进行截取
1856+ mkes [j ] = getValue (origin ).toString ();
1857+ continue ;
1858+ }
1859+ else if (ck .contains ("`" ) || ck .contains ("'" ) || origin .startsWith ("_" ) || origin .contains ("--" )) { // || PATTERN_FUNCTION.matcher(origin).matches() == false) {
1860+ throw new IllegalArgumentException ("字符 " + origin + " 不合法!"
1861+ + "预编译模式下 @column:\" column0,column1:alias;function0(arg0,arg1,...);function1(...):alias...\" "
1862+ + " 中所有 arg 都必须是1个不以 _ 开头的单词 或者符合正则表达式 " + PATTERN_FUNCTION + " 且不包含连续减号 -- !DISTINCT 必须全大写,且后面必须有且只有 1 个空格!其它情况不允许空格!" );
18271863 }
18281864
18291865 boolean isName = false ;
0 commit comments