alibaba / alibaba/fastjson2

[BUG] JSONObject.parse不正确

Open
#2,522 1 comment 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

### 问题描述
Fastjson中JSONObject.parse 与Fastjson2有差异

### 环境信息

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

### 重现步骤
```java
import com.alibaba.fastjson2.JSONException;
import com.alibaba.fastjson2.JSONObject;
import org.junit.jupiter.api.Test;

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

public class Issue2155Mutated_241 {
@Test
public void test() {
assertThrows(
JSONException.class,
() -> JSONObject.parse("{[1,2]}"));
}

@Test
public void test1() {
assertThrows(
com.alibaba.fastjson.JSONException.class,
() -> com.alibaba.fastjson.JSONObject.parse("{[1,2]}"));
}

}

```

### 期待的正确结果
`{[1,2]}` is an invalid json on https://jsonlint.com/
fastjson does not throw any exception

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

Contributor guide

Open the contributing guide

Research direction

Start at the JSONObject.parse entry points shown in the supplied JUnit reproducer and run the two assertions with the reported Fastjson 2.0.49 environment. Trace how the invalid input "{[1,2]}" is handled; done means both JSONObject.parse variants reject it with their respective JSONException types.

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
38/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.