fastjson2 icon indicating copy to clipboard operation
fastjson2 copied to clipboard

[BUG] JSONObject.parse不正确

Open Cooperzzy opened this issue 1 year ago • 1 comments

问题描述

Fastjson中JSONObject.parse 与Fastjson2有差异

环境信息

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

重现步骤

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.

Cooperzzy avatar May 06 '24 07:05 Cooperzzy

这个兼容API处理异常json的错误优先级不高,晚些时间再处理哈

wenshao avatar May 22 '24 22:05 wenshao