mirror of
https://gitee.com/chinabugotech/hutool.git
synced 2025-07-21 15:09:48 +08:00
fix slash escape bug
This commit is contained in:
@@ -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");
|
||||
|
@@ -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"));
|
||||
}
|
||||
|
||||
/**
|
||||
|
Reference in New Issue
Block a user