From c456062c17d46467a68a6c29621881c17a1d905e Mon Sep 17 00:00:00 2001 From: nanqi Date: Wed, 24 Jun 2020 13:36:34 +0800 Subject: [PATCH] bugfix for JSONValidator, fix #3293 --- .../com/alibaba/fastjson/JSONValidator.java | 5 +++- .../json/bvt/issue_3200/Issue3293.java | 27 +++++++++++++++++++ 2 files changed, 31 insertions(+), 1 deletion(-) create mode 100644 src/test/java/com/alibaba/json/bvt/issue_3200/Issue3293.java 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()); + } +}