alibaba / alibaba/fastjson2

[BUG] JSON.parseArray on illegal string with extra '{'

Open
#2,738 0 comments 0 reactions 0 assignees View on GitHub
bug
Dominant language
Java
Stars
4.4k
Forks
613
Avg merge
1d 22h
Merged PRs (30d)
6

Description

### 问题描述
#235, 字符串多了一个 '}',fastjson兼容JSON.parseArray未报错

### 环境信息

- OS信息: [MacOS 12.7.4 M1 Pro 16 GB]
- JDK信息: [Openjdk 17.0.6]
- 版本信息:[Fastjson 2.0.51]

### 重现步骤

```java
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONException;
import org.junit.jupiter.api.Test;
import java.util.List;
import static org.junit.jupiter.api.Assertions.assertThrows;

public class Issue235 {

@Test
public void testOriginalJsonParsing() {
String json = "[{\r\n"
+ " \"namespace\":\"unit07\", \r\n"
+ " \"items\":[\"COUNTER13_14.AV\",\r\n"
+ " \"COUNTER13_15.AV\"]\r\n"
+ "}\r\n"
+ "}]";

assertThrows(JSONException.class, () -> JSON.parseArray(json, TModal.class));
}

public static class TModal {
private String namespace;
private List items;

}
}
```

### 期待的正确结果
Maybe should throw an exception

### 相关日志输出
Expected com.alibaba.fastjson.JSONException to be thrown, but nothing was thrown.

Contributor guide

Open the contributing guide

Research direction

Start by running the supplied JUnit test for JSON.parseArray with the malformed array string, then trace the parser path used by JSON.parseArray. Done means the example consistently throws JSONException, with regression coverage for the reported input.

Written by the indexing model from the issue text.

Assessment

Tech stack
java
Domain
backend
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Clearly specified
Newbie friendliness
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.