Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[BUG] JSONPath.extract on illegal path #2580

Open
Cooper-Zhong opened this issue May 16, 2024 · 0 comments
Open

[BUG] JSONPath.extract on illegal path #2580

Cooper-Zhong opened this issue May 16, 2024 · 0 comments
Labels
bug Something isn't working

Comments

@Cooper-Zhong
Copy link

问题描述

JSONPath.extract对于illegal path抛出fastjson2.JSONException: TODO,fastjson 1.2.83 能够返回null

环境信息

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

重现步骤

import com.alibaba.fastjson2.JSONPath;
import org.junit.jupiter.api.Test;

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

public class Issue116Mutated_466 {
    String testJson = "{\"soap:Envelope\":{\"-xmlns:xsi\":\"http://www.w3.org/2001/XMLSchema-instance\",\"-xmlns:soap\":\"http://schemas.xmlsoap.org/soap/envelope/\",\"-xmlns:xsd\":\"http://www.w3.org/2001/XMLSchema\",\"soap:Body\":{\"getCountryCityByIpResponse\":{\"-xmlns\":\"http://WebXml.com.cn/\",\"getCountryCityByIpResult\":{\"string\":[\"30.40.202.24\",\"美国 俄亥俄州哥伦布市国防部网络信息中心\",\"30.40.202.25\"]}}}}}";

    @Test
    public void testMutated() {
        Object result = JSONPath.extract(testJson, "$.soap\\:Envelope.soap\\:Body.getCountryCityByIpResponse.getCountryCityByIpResult.string[*]");
        assertNotNull(result);
        assertEquals("[\"30.40.202.24\",\"美国 俄亥俄州哥伦布市国防部网络信息中心\",\"30.40.202.25\"]", result.toString());
    }

    @Test
    public void testMutated1() {
        Object result = JSONPath.extract(testJson, "$.soap\\:Envelope.soap\\:Body.getCountryCityByIpResponse.getCountryCityByIpResult.nothing[*]");
        assertNull(result);
    }

    @Test
    public void testMutated1fj() {
    // fastjson 1.2.83
        Object result = com.alibaba.fastjson.JSONPath.extract(testJson, "$.soap\\:Envelope.soap\\:Body.getCountryCityByIpResponse.getCountryCityByIpResult.nothing[*]");
        assertNull(result);
    }
}

期待的正确结果

返回null

相关日志输出

com.alibaba.fastjson2.JSONException: TODO
at com.alibaba.fastjson2.JSONPathSegment$AllSegment.accept(JSONPathSegment.java:1291)
at com.alibaba.fastjson2.JSONPathMulti.extract(JSONPathMulti.java:402)
at com.alibaba.fastjson2.JSONPath.extract(JSONPath.java:56)
at Issue116Mutated_466.testMutated1(Issue116Mutated_466.java:20)

@Cooper-Zhong Cooper-Zhong added the bug Something isn't working label May 16, 2024
@yanxutao89 yanxutao89 assigned yanxutao89 and unassigned yanxutao89 May 17, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants