diff --git a/src/main/java/com/alibaba/fastjson/parser/JSONLexer.java b/src/main/java/com/alibaba/fastjson/parser/JSONLexer.java index 424703bfa..32ddc42d1 100644 --- a/src/main/java/com/alibaba/fastjson/parser/JSONLexer.java +++ b/src/main/java/com/alibaba/fastjson/parser/JSONLexer.java @@ -3578,7 +3578,7 @@ public final class JSONLexer { char dot = charAt(bp + 19); if (dot == '.') { - if (rest < 23) { // 0000-00-00T00:00:00.000 + if (rest < 21) { // 0000-00-00T00:00:00.000 return false; } } else { @@ -3608,7 +3608,7 @@ public final class JSONLexer { int millis = digits[S0]; int millisLen = 1; - { + if (rest > 21) { char S1 = charAt(bp + 21); if (S1 >= '0' && S1 <= '9') { millis = millis * 10 + digits[S1]; diff --git a/src/test/java/com/alibaba/json/bvt/bug/Issue987.java b/src/test/java/com/alibaba/json/bvt/bug/Issue987.java new file mode 100644 index 000000000..f086d8eb1 --- /dev/null +++ b/src/test/java/com/alibaba/json/bvt/bug/Issue987.java @@ -0,0 +1,20 @@ +package com.alibaba.json.bvt.bug; + +import com.alibaba.fastjson.JSON; +import junit.framework.TestCase; + +import java.util.Date; + +/** + * Created by wenshao on 11/01/2017. + */ +public class Issue987 extends TestCase { + public void test_for_issue() throws Exception { + String text = "{\"date\":\"2016-11-09T09:57:20.4Z\"}"; + JSON.parseObject(text, Model.class); + } + + public static class Model { + public Date date; + } +} diff --git a/src/test/java/com/alibaba/json/bvt/parser/JSONScannerTest_ISO8601.java b/src/test/java/com/alibaba/json/bvt/parser/JSONScannerTest_ISO8601.java index f4e8cc718..ac470dd37 100755 --- a/src/test/java/com/alibaba/json/bvt/parser/JSONScannerTest_ISO8601.java +++ b/src/test/java/com/alibaba/json/bvt/parser/JSONScannerTest_ISO8601.java @@ -88,8 +88,8 @@ public class JSONScannerTest_ISO8601 extends TestCase { Assert.assertEquals(false, new JSONLexer("2000-02-10T00:00:A0").scanISO8601DateIfMatch(true)); Assert.assertEquals(true, new JSONLexer("2000-02-10T00:00:00").scanISO8601DateIfMatch(true)); Assert.assertEquals(false, new JSONLexer("2000-02-10T00:00:00.").scanISO8601DateIfMatch(true)); - Assert.assertEquals(false, new JSONLexer("2000-02-10T00:00:00.0").scanISO8601DateIfMatch(true)); - Assert.assertEquals(false, new JSONLexer("2000-02-10T00:00:00.00").scanISO8601DateIfMatch(true)); + Assert.assertEquals(true, new JSONLexer("2000-02-10T00:00:00.0").scanISO8601DateIfMatch(true)); + Assert.assertEquals(true, new JSONLexer("2000-02-10T00:00:00.00").scanISO8601DateIfMatch(true)); Assert.assertEquals(true, new JSONLexer("2000-02-10T00:00:00.000").scanISO8601DateIfMatch(true)); Assert.assertEquals(false, new JSONLexer("2000-02-10T00:00:00.A00").scanISO8601DateIfMatch(true)); Assert.assertEquals(false, new JSONLexer("2000-02-10T00:00:00.!00").scanISO8601DateIfMatch(true));