bug fixed

This commit is contained in:
wenshao
2014-10-03 02:01:10 +08:00
parent 037b84527d
commit 19bfc248f2
6 changed files with 97 additions and 1 deletions
@@ -20,6 +20,7 @@ import java.io.IOException;
import java.io.Reader;
import java.io.StringReader;
import java.lang.ref.SoftReference;
import java.util.Arrays;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONException;
@@ -166,11 +167,15 @@ public final class JSONReaderScanner extends JSONLexerBase {
try {
int startPos = bp;
int readLength = buf.length - startPos;
if (readLength == 0) {
buf = Arrays.copyOf(buf, buf.length * 2);
readLength = buf.length - startPos;
}
bufLength = reader.read(buf, bp, readLength);
} catch (IOException e) {
throw new JSONException(e.getMessage(), e);
}
if (bufLength == 0) {
throw new JSONException("illegal stat, textLength is zero");
}
@@ -0,0 +1,15 @@
package com.alibaba.json.bvt.bug;
import junit.framework.TestCase;
import com.alibaba.fastjson.JSONObject;
public class Issue126 extends TestCase {
public void test_for_issue() throws Exception {
JSONObject j = new JSONObject();
j.put("content",
"爸爸去哪儿-第十期-萌娃比赛小猪快跑 爸爸上演\"百变大咖秀\"-【湖南卫视官方版1080P】20131213: http://youtu.be/ajvaXKAduJ4 via @youtube");
System.out.println(j.toJSONString());
}
}
@@ -0,0 +1,19 @@
package com.alibaba.json.bvt.bug;
import java.util.HashMap;
import java.util.Map;
import junit.framework.TestCase;
import com.alibaba.fastjson.JSON;
public class Issue171 extends TestCase {
public void test_for_issue() throws Exception {
Map m = new HashMap();
m.put("a", "\u000B");
String json = JSON.toJSONString(m);
System.out.println(json);
JSON.parse(json);
}
}
@@ -0,0 +1,36 @@
package com.alibaba.json.bvt.bug;
import java.io.InputStream;
import java.io.InputStreamReader;
import junit.framework.TestCase;
import com.alibaba.fastjson.JSONReader;
import com.alibaba.fastjson.util.IOUtils;
public class Issue72 extends TestCase {
public void test_for_issue() throws Exception {
InputStream is = Issue72.class.getClassLoader().getResourceAsStream("issue72.json");
JSONReader reader = null;
try {
byte[] rowBatchBytes = null;
byte[] fileBatchBytes = null;
reader = new JSONReader(new InputStreamReader(is));
reader.startArray();
while (reader.hasNext()) {
if (rowBatchBytes == null) {
rowBatchBytes = reader.readObject(byte[].class);
} else if (fileBatchBytes == null) {
fileBatchBytes = reader.readObject(byte[].class);
} else {
throw new Exception("archive data json parse failed!");
}
}
reader.endArray();
} finally {
IOUtils.close(reader);
}
}
}
@@ -0,0 +1,20 @@
package com.alibaba.json.bvt.bug;
import org.junit.Assert;
import junit.framework.TestCase;
import com.alibaba.fastjson.JSON;
public class Issue89 extends TestCase {
public void test_for_issue() throws Exception {
Exception error = null;
try {
JSON.parse("{\"a\":з」∠)_,\"}");
} catch (Exception ex) {
error = ex;
}
Assert.assertNotNull(error);
}
}
File diff suppressed because one or more lines are too long