fix slash escape bug

This commit is contained in:
Looly
2020-04-25 09:31:39 +08:00
parent 669d19eab8
commit 2bcad6031d
5 changed files with 24 additions and 13 deletions

View File

@@ -142,6 +142,15 @@ public class JSONObjectTest {
Console.log(json2);
}
@Test
public void parseStringWithSlashTest() {
//在5.3.2之前,</div>中的/会被转义修复此bug的单元测试
String jsonStr = "{\"a\":\"<div>aaa</div>\"}";
JSONObject json = new JSONObject(jsonStr);
Assert.assertEquals("<div>aaa</div>", json.get("a"));
Assert.assertEquals(jsonStr, json.toString());
}
@Test
public void toBeanTest() {
JSONObject subJson = JSONUtil.createObj().set("value1", "strValue1").set("value2", "234");

View File

@@ -93,11 +93,11 @@ public class JSONUtilTest {
map.put("user", object.toString());
JSONObject json = JSONUtil.parseObj(map);
Assert.assertEquals("{\"name\":\"123123\",\"value\":\"\\\\\",\"value2\":\"<\\/\"}", json.get("user"));
Assert.assertEquals("{\"user\":\"{\\\"name\\\":\\\"123123\\\",\\\"value\\\":\\\"\\\\\\\\\\\",\\\"value2\\\":\\\"<\\\\/\\\"}\"}", json.toString());
Assert.assertEquals("{\"name\":\"123123\",\"value\":\"\\\\\",\"value2\":\"</\"}", json.get("user"));
Assert.assertEquals("{\"user\":\"{\\\"name\\\":\\\"123123\\\",\\\"value\\\":\\\"\\\\\\\\\\\",\\\"value2\\\":\\\"</\\\"}\"}", json.toString());
JSONObject json2 = JSONUtil.parseObj(json.toString());
Assert.assertEquals("{\"name\":\"123123\",\"value\":\"\\\\\",\"value2\":\"<\\/\"}", json2.get("user"));
Assert.assertEquals("{\"name\":\"123123\",\"value\":\"\\\\\",\"value2\":\"</\"}", json2.get("user"));
}
/**