Skip to content

Commit

Permalink
fix parse single quote utf8 bytes input error, for issue #2067
Browse files Browse the repository at this point in the history
  • Loading branch information
wenshao committed Dec 2, 2023
1 parent 4cc05ab commit b8519bf
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -6136,7 +6136,7 @@ public String readString() {
}
chars[i] = (char) c;
offset++;
} else if (c == '"') {
} else if (c == quote) {
break;
} else {
if (c >= 0) {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
package com.alibaba.fastjson2.issues_2000;

import com.alibaba.fastjson2.JSON;
import com.alibaba.fastjson2.JSONObject;
import org.junit.jupiter.api.Test;

import java.nio.charset.StandardCharsets;

import static org.junit.jupiter.api.Assertions.assertEquals;

public class Issue2067 {
@Test
public void test() {
String str = "{'code':3006,'data':{'betList':[5,10,20,50,100],'buyCards':[],'cur_round':0,'mapId':40,'my_player':'{\\'uid\\':13730840,\\'nickname\\':\\'王10\\',\\'sex\\':0,\\'headimgurl\\':\\'http://thirdwsx.qlogo.cn/mmopen/vi_32/s0tWG8WNxdfUjicicle40ODeyHBt8DttcKAw5zbgwgsEru2hMPdiasd2gH68Vz8Tx0smvlwjN2GydWj7ia4tUJPYHicA/132\\',\\'client_pos\\':0,\\'is_offline\\':false,\\'is_viewer\\':1,\\'ivpanr\\':1,\\'balance\\':1000.0,\\'totalPay\\':0.0,\\'totalPayCnt\\':0}','roomId':164509742}}";
byte[] bytes = str.getBytes(StandardCharsets.UTF_8);
assertEquals(
JSON.parseObject(str, JSONObject.class),
JSON.parseObject(bytes, JSONObject.class));
assertEquals(
JSON.parseObject(str.toCharArray(), JSONObject.class),
JSON.parseObject(bytes, JSONObject.class));
}
}

0 comments on commit b8519bf

Please sign in to comment.