Skip to content

Commit

Permalink
add testcase
Browse files Browse the repository at this point in the history
  • Loading branch information
wenshao committed Apr 28, 2016
1 parent 9a3017c commit 2a746a5
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 10 deletions.
4 changes: 2 additions & 2 deletions src/main/java/com/alibaba/fastjson/parser/JSONLexerBase.java
Expand Up @@ -1721,7 +1721,7 @@ public int scanFieldInt(char[] fieldName) {
break;
}
}
if (value < 0) {
if (value < 0 || offset > 11) {
matchStat = NOT_MATCH;
return 0;
}
Expand Down Expand Up @@ -1999,7 +1999,7 @@ public long scanFieldLong(char[] fieldName) {
break;
}
}
if (value < 0) {
if (value < 0 || offset > 21) {
matchStat = NOT_MATCH;
return 0;
}
Expand Down
Expand Up @@ -13,7 +13,7 @@

public class ReaderIntFieldTest extends TestCase {

public void test_long_error_0() throws Exception {
public void test_int_error_0() throws Exception {
Exception error = null;
try {
JSONReader reader = new JSONReader(new StringReader("{\"value\":1.A}"));
Expand All @@ -24,18 +24,40 @@ public void test_long_error_0() throws Exception {
Assert.assertNotNull(error);
}

public void test_long_error_1() throws Exception {
public void test_int_error_1() throws Exception {
Exception error = null;
try {
JSONReader reader = new JSONReader(new StringReader("{\"value\":2147483648,"));
JSONReader reader = new JSONReader(new StringReader("{\"value\":2147483648}"));
reader.readObject(Model.class);
} catch (JSONException ex) {
error = ex;
}
Assert.assertNotNull(error);
}

public void test_int_error_1_x() throws Exception {
Exception error = null;
try {
JSONReader reader = new JSONReader(new StringReader("{\"value\":9223372036854775808}"));
reader.readObject(Model.class);
} catch (JSONException ex) {
error = ex;
}
Assert.assertNotNull(error);
}

public void test_int_error_1_x1() throws Exception {
Exception error = null;
try {
JSONReader reader = new JSONReader(new StringReader("{\"value\":-2147483649}"));
reader.readObject(Model.class);
} catch (JSONException ex) {
error = ex;
}
Assert.assertNotNull(error);
}

public void test_long_error_2() throws Exception {
public void test_int_error_2() throws Exception {
Exception error = null;
try {
JSONReader reader = new JSONReader(new StringReader("{\"value\":AA}"));
Expand All @@ -46,15 +68,15 @@ public void test_long_error_2() throws Exception {
Assert.assertNotNull(error);
}

public void test_long_normal() throws Exception {
public void test_int_normal() throws Exception {
JSONReader reader = new JSONReader(new StringReader("{\"value\":1001,\"value2\":-2001}"));
Model model = reader.readObject(Model.class);
Assert.assertEquals(1001, model.value);
Assert.assertEquals(-2001, model.value2);
reader.close();
}

public void test_long_normal_2() throws Exception {
public void test_int_normal_2() throws Exception {
JSONReader reader = new JSONReader(new StringReader("{\"model\":{\"value\":3001,\"value2\":-4001}}"));
Map<String, Model> map = reader.readObject(new TypeReference<Map<String, Model>>() {
});
Expand All @@ -64,7 +86,7 @@ public void test_long_normal_2() throws Exception {
reader.close();
}

public void test_long_error_map() throws Exception {
public void test_int_error_map() throws Exception {
Exception error = null;
try {
JSONReader reader = new JSONReader(new StringReader("{\"model\":{\"value\":3001,\"value2\":-4001}["));
Expand All @@ -76,7 +98,7 @@ public void test_long_error_map() throws Exception {
Assert.assertNotNull(error);
}

public void test_long_error_end() throws Exception {
public void test_int_error_end() throws Exception {
Exception error = null;
try {
JSONReader reader = new JSONReader(new StringReader("{\"value\":1001,\"value2\":-2001["));
Expand Down
Expand Up @@ -34,6 +34,17 @@ public void test_long_error_1() throws Exception {
}
Assert.assertNotNull(error);
}

public void test_long_error_1_x() throws Exception {
Exception error = null;
try {
JSONReader reader = new JSONReader(new StringReader("{\"value\":922337203685477580892233720368547758088}"));
reader.readObject(Model.class);
} catch (JSONException ex) {
error = ex;
}
Assert.assertNotNull(error);
}

public void test_long_error_2() throws Exception {
Exception error = null;
Expand Down

0 comments on commit 2a746a5

Please sign in to comment.