fastjson2 icon indicating copy to clipboard operation
fastjson2 copied to clipboard

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

Open Cooperzzy opened this issue 1 year ago • 0 comments

问题描述

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

环境信息

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

重现步骤

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<String> items;

    }
}

期待的正确结果

Maybe should throw an exception

相关日志输出

Expected com.alibaba.fastjson.JSONException to be thrown, but nothing was thrown.

Cooperzzy avatar Jun 25 '24 14:06 Cooperzzy