Skip to content

Commit

Permalink
bug fixed for \u001A serialize, fixed issue 304. alibaba#304
Browse files Browse the repository at this point in the history
  • Loading branch information
wenshao committed Apr 13, 2016
1 parent c25af86 commit fc56dca
Show file tree
Hide file tree
Showing 2 changed files with 51 additions and 0 deletions.
8 changes: 8 additions & 0 deletions src/main/java/com/alibaba/fastjson/parser/JSONLexerBase.java
Original file line number Diff line number Diff line change
Expand Up @@ -856,6 +856,10 @@ public final void scanString() {
}

if (ch == EOI) {
if (!isEOF()) {
putChar((char) EOI);
continue;
}
throw new JSONException("unclosed string : " + ch);
}

Expand Down Expand Up @@ -2639,6 +2643,10 @@ private void scanStringSingleQuote() {
}

if (chLocal == EOI) {
if (!isEOF()) {
putChar((char) EOI);
continue;
}
throw new JSONException("unclosed single-quote string");
}

Expand Down
43 changes: 43 additions & 0 deletions src/test/java/com/alibaba/json/bvt/bug/Bug_for_issue_304.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
package com.alibaba.json.bvt.bug;

import org.junit.Assert;

import com.alibaba.fastjson.JSON;

import junit.framework.TestCase;

public class Bug_for_issue_304 extends TestCase {

public void test_doubleQuote() throws Exception {
String ss = "{\"value\":\"Intki_E96?\u001A Build\"}";
Assert.assertEquals("Intki_E96?\u001A Build", JSON.parseObject(ss).get("value"));
}

public void test_doubleQuote_vo() throws Exception {
String ss = "{\"value\":\"Intki_E96?\u001A Build\"}";
Assert.assertEquals("Intki_E96?\u001A Build", JSON.parseObject(ss, VO.class).value);
}

public void test_doubleQuote_vo_private() throws Exception {
String ss = "{\"value\":\"Intki_E96?\u001A Build\"}";
Assert.assertEquals("Intki_E96?\u001A Build", JSON.parseObject(ss, V1.class).value);
}

public void test_singleQuote() throws Exception {
String ss = "{'value':'Intki_E96?\u001A Build'}";
Assert.assertEquals("Intki_E96?\u001A Build", JSON.parseObject(ss).get("value"));
}

public void test_singleQuote_vo() throws Exception {
String ss = "{'value':'Intki_E96?\u001A Build'}";
Assert.assertEquals("Intki_E96?\u001A Build", JSON.parseObject(ss, VO.class).value);
}

public static class VO {
public String value;
}

private static class V1 {
public String value;
}
}

0 comments on commit fc56dca

Please sign in to comment.