Skip to content
This repository has been archived by the owner on Oct 23, 2024. It is now read-only.

Commit

Permalink
improved JSONValidator, fix #3516
Browse files Browse the repository at this point in the history
  • Loading branch information
wenshao committed Nov 5, 2020
1 parent 13f3f2b commit ab13b03
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 0 deletions.
9 changes: 9 additions & 0 deletions src/main/java/com/alibaba/fastjson/JSONValidator.java
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ public enum Type {
protected int pos = -1;
protected char ch;
protected Type type;
private Boolean valiateResult;

protected int count = 0;
protected boolean supportMultiValue = false;
Expand Down Expand Up @@ -54,13 +55,19 @@ public Type getType() {
abstract void next();

public boolean validate() {
if (valiateResult != null) {
return valiateResult;
}

for (;;) {
if (!any()) {
valiateResult = false;
return false;
}

count++;
if (eof) {
valiateResult = true;
return true;
}

Expand All @@ -71,10 +78,12 @@ public boolean validate() {
}
continue;
} else {
valiateResult = false;
return false;
}
}

valiateResult = true;
return true;
}

Expand Down
12 changes: 12 additions & 0 deletions src/test/java/com/alibaba/json/bvt/issue_3500/Issue3516.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
package com.alibaba.json.bvt.issue_3500;

import com.alibaba.fastjson.JSONValidator;
import junit.framework.TestCase;

public class Issue3516 extends TestCase {
public void test_for_issue() throws Exception {
JSONValidator validator = JSONValidator.from("{}");
assertEquals(JSONValidator.Type.Object, validator.getType());
assertTrue(validator.validate());
}
}

0 comments on commit ab13b03

Please sign in to comment.