Visitar URL original
Server:优化访问限制的计算及报错 · skymoon08/APIJSON@7a1a4c8 · GitHub
Skip to content

Commit 7a1a4c8

Browse files
committed
Server:优化访问限制的计算及报错
1 parent 51cbea9 commit 7a1a4c8

2 files changed

Lines changed: 16 additions & 13 deletions

File tree

‎APIJSON-Java-Server/APIJSONORM/src/main/java/zuo/biao/apijson/server/AbstractObjectParser.java‎

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -484,12 +484,12 @@ public JSON onChildParse(int index, String key, JSONObject value) throws Excepti
484484
boolean isEmpty;
485485

486486
if (zuo.biao.apijson.JSONObject.isArrayKey(key)) {//APIJSON Array
487-
int maxArrayCount = parser.getMaxArrayCount();
488-
if (arrayCount > maxArrayCount) {
489-
throw new IllegalArgumentException(path + " 内 key[]:{} 的数量 为 " + arrayCount + " 已超限,必须在 0-" + maxArrayCount + " 内 !");
490-
}
491487
if (arrayConfig == null || arrayConfig.getPosition() == 0) {
492488
arrayCount ++;
489+
int maxArrayCount = parser.getMaxArrayCount();
490+
if (arrayCount > maxArrayCount) {
491+
throw new IllegalArgumentException(path + " 内截至 " + key + " 时数组对象 key[]:{} 的数量达到 " + arrayCount + " 已超限,必须在 0-" + maxArrayCount + " 内 !");
492+
}
493493
}
494494

495495
if (isMain) {
@@ -501,12 +501,12 @@ public JSON onChildParse(int index, String key, JSONObject value) throws Excepti
501501
isEmpty = child == null || ((JSONArray) child).isEmpty();
502502
}
503503
else {//APIJSON Object
504-
int maxObjectCount = parser.getMaxObjectCount();
505-
if (objectCount > maxObjectCount) {
506-
throw new IllegalArgumentException(path + " 内 TableKey:{} 的数量 为 " + objectCount + " 已超限,必须在 0-" + maxObjectCount + " 内 !");
507-
}
508504
if (arrayConfig == null || arrayConfig.getPosition() == 0) {
509505
arrayCount ++;
506+
int maxObjectCount = parser.getMaxObjectCount();
507+
if (objectCount > maxObjectCount) {
508+
throw new IllegalArgumentException(path + " 内截至 " + key + " 时表对象 TableKey:{} 的数量达到 " + objectCount + " 已超限,必须在 0-" + maxObjectCount + " 内 !");
509+
}
510510
}
511511

512512
if (type == TYPE_ITEM && JSONRequest.isTableKey(Pair.parseEntry(key, true).getKey()) == false) {

‎APIJSON-Java-Server/APIJSONORM/src/main/java/zuo/biao/apijson/server/AbstractParser.java‎

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -640,10 +640,13 @@ public JSONObject onObjectParse(final JSONObject request
640640

641641
String[] arr = StringUtil.split(parentPath, "/");
642642
if (arrayConfig == null || arrayConfig.getPosition() == 0) {
643-
queryDepth = arr == null ? 0 : arr.length;
644-
int maxQueryDepth = getMaxQueryDepth();
645-
if (queryDepth > maxQueryDepth) {
646-
throw new IllegalArgumentException(parentPath + "/" + name + ":{} 的深度(或者说层级) 为 " + queryDepth + " 已超限,必须在 0-" + maxQueryDepth + " 内 !");
643+
int d = arr == null ? 1 : arr.length + 1;
644+
if (queryDepth < d) {
645+
queryDepth = d;
646+
int maxQueryDepth = getMaxQueryDepth();
647+
if (queryDepth > maxQueryDepth) {
648+
throw new IllegalArgumentException(parentPath + "/" + name + ":{} 的深度(或者说层级) 为 " + queryDepth + " 已超限,必须在 1-" + maxQueryDepth + " 内 !");
649+
}
647650
}
648651
}
649652

@@ -1282,7 +1285,7 @@ public synchronized JSONObject executeSQL(@NotNull SQLConfig config, boolean isS
12821285
int maxSQLCount = getMaxSQLCount();
12831286
Log.d(TAG, "<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< \n\n\n 已生成 " + sqlCount + "/" + maxSQLCount + "条 SQL \n\n\n >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>");
12841287
if (sqlCount > maxSQLCount) {
1285-
throw new IllegalArgumentException("已生成 " + sqlCount + "条 SQL,数量已超限,必须在 0-" + maxSQLCount + " 内 !");
1288+
throw new IllegalArgumentException("截至 " + config.getTable() + " 已生成 " + sqlCount + "条 SQL,数量已超限,必须在 0-" + maxSQLCount + " 内 !");
12861289
}
12871290

12881291
try {

0 commit comments

Comments
 (0)