diff --git a/src/main/java/com/alibaba/fastjson/JSONValidator.java b/src/main/java/com/alibaba/fastjson/JSONValidator.java index 13c9d4c168..deec6f52d0 100644 --- a/src/main/java/com/alibaba/fastjson/JSONValidator.java +++ b/src/main/java/com/alibaba/fastjson/JSONValidator.java @@ -58,8 +58,11 @@ public boolean validate() { } count++; + if (eof) { + return true; + } - if (supportMultiValue && !eof) { + if (supportMultiValue) { skipWhiteSpace(); if (eof) { break; diff --git a/src/test/java/com/alibaba/json/bvt/issue_3200/Issue3293.java b/src/test/java/com/alibaba/json/bvt/issue_3200/Issue3293.java new file mode 100644 index 0000000000..a78dc4d56d --- /dev/null +++ b/src/test/java/com/alibaba/json/bvt/issue_3200/Issue3293.java @@ -0,0 +1,27 @@ +package com.alibaba.json.bvt.issue_3200; + +import com.alibaba.fastjson.JSONValidator; +import junit.framework.TestCase; +import org.junit.Assert; + +/** + * @Author :Nanqi + * @Date :Created in 09:59 2020/6/24 + */ +public class Issue3293 extends TestCase { + public void test_for_issue() throws Exception { + JSONValidator jv = JSONValidator.from("{\"a\"}"); + Assert.assertFalse(jv.validate()); + + jv = JSONValidator.from("113{}[]"); + jv.setSupportMultiValue(false); + Assert.assertFalse(jv.validate()); + Assert.assertEquals(JSONValidator.Type.Value, jv.getType()); + + jv = JSONValidator.from("{\"a\":\"12333\"}"); + Assert.assertTrue(jv.validate()); + + jv = JSONValidator.from("{}"); + Assert.assertTrue(jv.validate()); + } +}