@@ -243,7 +243,7 @@ public String getGroupString() {
243243 if (group .isEmpty ()) {
244244 return "" ;
245245 }
246-
246+
247247 if (isPrepared ()) { //不能通过 ? 来代替,因为SQLExecutor statement.setString后 GROUP BY 'userId' 有单引号,只能返回一条数据,必须去掉单引号才行!
248248 String [] keys = StringUtil .split (group );
249249 if (keys != null && keys .length > 0 ) {
@@ -306,7 +306,7 @@ public String getOrderString() {
306306 if (order .contains ("-" )) {
307307 order = order .replaceAll ("-" , " DESC " );
308308 }
309-
309+
310310 if (isPrepared ()) { //不能通过 ? 来代替,SELECT 'id','name' 返回的就是 id:"id", name:"name",而不是数据库里的值!
311311 String [] keys = StringUtil .split (order );
312312 if (keys != null && keys .length > 0 ) {
@@ -318,16 +318,16 @@ public String getOrderString() {
318318 index = keys [i ].trim ().endsWith (" DESC" ) ? keys [i ].lastIndexOf (" DESC" ) : -1 ;
319319 }
320320 origin = index < 0 ? keys [i ] : keys [i ].substring (0 , index );
321-
322- //这里既不对origin trim,也不对 ASC/DESC ignoreCase,希望前端严格传没有任何空格的字符串过来,减少传输数据量,节约服务器性能
321+
322+ //这里既不对origin trim,也不对 ASC/DESC ignoreCase,希望前端严格传没有任何空格的字符串过来,减少传输数据量,节约服务器性能
323323 if (StringUtil .isName (origin ) == false ) {
324324 throw new IllegalArgumentException ("预编译模式下 @order:value 中 value里面用 , 分割的每一项"
325325 + " column+ / column- 中 column必须是1个单词!并且不要有多余的空格!" );
326326 }
327327 }
328328 }
329329 }
330-
330+
331331 return " ORDER BY " + order ;
332332 }
333333
@@ -351,7 +351,7 @@ public String getColumnString() throws NotExistException {
351351 case HEAD :
352352 case HEADS : //StringUtil.isEmpty(column, true) || column.contains(",") 时SQL.count(column)会return "*"
353353 if (isPrepared () && StringUtil .isEmpty (column , true ) == false
354- && column .contains ("," ) == false && StringUtil .isName (column ) == false ) {
354+ && column .contains ("," ) == false && StringUtil .isName (column ) == false ) {
355355 throw new IllegalArgumentException ("HEAD请求: @column:value 中 value里面用 , 分割的每一项都必须是1个单词!" );
356356 }
357357 return SQL .count (column );
@@ -360,7 +360,7 @@ public String getColumnString() throws NotExistException {
360360 throw new NotExistException (TAG + "getColumnString getMethod() = POST"
361361 + " >> StringUtil.isEmpty(column, true)" );
362362 }
363-
363+
364364 if (isPrepared ()) { //不能通过 ? 来代替,SELECT 'id','name' 返回的就是 id:"id", name:"name",而不是数据库里的值!
365365 String [] keys = StringUtil .split (column );
366366 if (keys != null && keys .length > 0 ) {
@@ -371,14 +371,14 @@ public String getColumnString() throws NotExistException {
371371 }
372372 }
373373 }
374-
374+
375375 return "(" + column + ")" ;
376376 default :
377377 column = StringUtil .getString (column );
378378 if (column .isEmpty ()) {
379379 return "*" ;
380380 }
381-
381+
382382 if (isPrepared ()) { //不能通过 ? 来代替,SELECT 'id','name' 返回的就是 id:"id", name:"name",而不是数据库里的值!
383383 String [] keys = StringUtil .split (column );
384384 if (keys != null && keys .length > 0 ) {
@@ -389,15 +389,15 @@ public String getColumnString() throws NotExistException {
389389 index = keys [i ].indexOf (":" ); //StringUtil.split返回数组中,子项不会有null
390390 origin = index < 0 ? keys [i ] : keys [i ].substring (0 , index );
391391 alias = index < 0 ? null : keys [i ].substring (index + 1 );
392-
392+
393393 if (StringUtil .isName (origin ) == false || (alias != null && StringUtil .isName (alias ) == false )) {
394394 throw new IllegalArgumentException ("GET请求: 预编译模式下 @column:value 中 value里面用 , 分割的每一项"
395395 + " column:alias 中 column必须是1个单词!如果有alias,则alias也必须为1个单词!并且不要有多余的空格!" );
396396 }
397397 }
398398 }
399399 }
400-
400+
401401 return column .contains (":" ) == false ? column : column .replaceAll (":" , " AS " );//不能在这里改,后续还要用到:
402402 }
403403 }
@@ -421,7 +421,7 @@ public AbstractSQLConfig setValues(Object[][] valuess) {
421421 if (vs == null ) {
422422 continue ;
423423 }
424-
424+
425425 items [i ] = "(" ;
426426 for (int j = 0 ; j < vs .length ; j ++) {
427427 items [i ] += ((j <= 0 ? "" : "," ) + getValue (vs [j ]));
@@ -858,14 +858,14 @@ public String getRegExpString(String key, String value) {
858858
859859
860860 //{} range <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
861-
861+
862862 // * 和 / 不能同时出现,防止 /* */ 段注释! # 和 -- 不能出现,防止行注释! ; 不能出现,防止隔断SQL语句!空格不能出现,防止 CRUD,DROP,SHOW TABLES等语句!
863863 private static final Pattern PATTERN_RANGE ;
864864 static {
865865 PATTERN_RANGE = Pattern .compile ("^[0-9%!=<>,]+$" ); // ^[a-zA-Z0-9_*%!=<>(),"]+$ 导致 exists(select*from(Comment)) 通过!
866866 }
867867
868-
868+
869869 /**WHERE key > 'key0' AND key <= 'key1' AND ...
870870 * @param key
871871 * @param range "condition0,condition1..."
@@ -893,7 +893,7 @@ public String getRangeString(String key, Object range) throws Exception {
893893 if (isPrepared () && PATTERN_RANGE .matcher ((String ) range ).matches () == false ) {
894894 throw new UnsupportedOperationException ("字符串 " + range + " 不合法!预编译模式下 key{}:\" condition\" 中 condition 必须符合正则表达式 ^[0-9%!=<>,]+$ !不允许空格!" );
895895 }
896-
896+
897897 String [] conditions = StringUtil .split ((String ) range );
898898 String condition = "" ;
899899 if (conditions != null ) {
@@ -1344,13 +1344,16 @@ public static AbstractSQLConfig newSQLConfig(RequestMethod method, String table,
13441344 Object value ;
13451345 for (String key : set ) {
13461346 value = request .get (key );
1347- if (value instanceof JSONObject == false ) {//只允许常规Object
1348- //解决AccessVerifier新增userId没有作为条件,而是作为内容,导致PUT,DELETE出错
1349- if (isWhere || (conditionList != null && conditionList .contains (key ))) {
1350- tableWhere .put (key , value );
1351- } else {
1352- tableContent .put (key , value );//一样 instanceof JSONArray ? JSON.toJSONString(value) : value);
1353- }
1347+
1348+ if (value instanceof Map ) {//只允许常规Object
1349+ throw new IllegalArgumentException ("不允许 " + key + " 等任何key的value类型为 {JSONObject} !" );
1350+ }
1351+
1352+ //解决AccessVerifier新增userId没有作为条件,而是作为内容,导致PUT,DELETE出错
1353+ if (isWhere || (conditionList != null && conditionList .contains (key ))) {
1354+ tableWhere .put (key , value );
1355+ } else {
1356+ tableContent .put (key , value );//一样 instanceof JSONArray ? JSON.toJSONString(value) : value);
13541357 }
13551358 }
13561359
0 commit comments