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] Exception in JSONPath.eval #2585

Closed
Cooper-Zhong opened this issue May 16, 2024 · 3 comments
Closed

[BUG] Exception in JSONPath.eval #2585

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

Comments

@Cooper-Zhong
Copy link

问题描述

JSONPath.eval 两个不同字符串时抛exception,以下代码在fastjson 1.2.83中均通过,感觉是个问题

环境信息

  • 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.assertEquals;

public class Issue1965_757_2 {

    @Test
    public void testMutant1() {
        String str1 = "{\"data\": [1]}";
        String str2 = "{\n" +
                "  \"code\": \"1003\", \n" +
                "  \"data\": [1], \n" +
                "  \"message\": \"code: 1003,以【你好】开头的句子的长度不符合要求, 长度限制:3~500,实际长度:2\"\n" +
                "}\n";
        System.out.println(str1);
        System.out.println(str2);
        Object obj1 = JSONPath.eval(
                str1, "$.data[0][0]");
        Object obj2 = JSONPath.eval(
                str2, "$.data[0][0]");
        assertEquals(obj1, obj2);
    }

    @Test
    public void testMutant2() {
        String str1 = "{\"data\": [1,2]}";
        String str2 = "{\n" +
                "  \"code\": \"1003\", \n" +
                "  \"data\": [1,2], \n" +
                "  \"message\": \"code: 1003,以【你好】开头的句子的长度不符合要求, 长度限制:3~500,实际长度:2\"\n" +
                "}\n";
        System.out.println(str1);
        System.out.println(str2);
        assertEquals(
                JSONPath.eval(str1, "$.data[0][0]"),
                JSONPath.eval(str2, "$.data[0][0]"));
    }

    @Test
    public void testMutant3() {
        String str1 = "{\"data\": [{\"id\":\"1\"}]}";
        String str2 = "{\n" +
                "  \"code\": \"1003\", \n" +
                "  \"data\": [{\"id\":\"1\"}], \n" +
                "  \"message\": \"code: 1003,以【你好】开头的句子的长度不符合要求, 长度限制:3~500,实际长度:2\"\n" +
                "}\n";
        System.out.println(str1);
        System.out.println(str2);
        assertEquals(
                JSONPath.eval(str1, "$.data[0][0]"),
                JSONPath.eval(str2, "$.data[0][0]"));
    }

}

相关日志输出

com.alibaba.fastjson2.JSONValidException: error, offset 51, char :
at com.alibaba.fastjson2.JSONReader.error(JSONReader.java:4544)
at com.alibaba.fastjson2.JSONReaderUTF16.skipValue(JSONReaderUTF16.java:3726)
at com.alibaba.fastjson2.JSONPathSegmentIndex.accept(JSONPathSegmentIndex.java:489)
at com.alibaba.fastjson2.JSONPathMulti.extract(JSONPathMulti.java:402)
at com.alibaba.fastjson2.JSONPath.extract(JSONPath.java:56)
at com.alibaba.fastjson2.JSONPath.eval(JSONPath.java:66)
at Issue1965_757_2.testMutant2(Issue1965_757_2.java:39)

@Cooper-Zhong Cooper-Zhong added the bug Something isn't working label May 16, 2024
wenshao added a commit that referenced this issue May 16, 2024
@wenshao wenshao added this to the 2.0.51 milestone May 16, 2024
@wenshao wenshao added the fixed label May 16, 2024
@wenshao
Copy link
Member

wenshao commented May 16, 2024

https://oss.sonatype.org/content/repositories/snapshots/com/alibaba/fastjson2/fastjson2/2.0.51-SNAPSHOT/
问题已修复,请帮忙用2.0.51-SNAPSHOT版本验证

@Cooper-Zhong
Copy link
Author

验证已修复,辛苦温少

@wenshao
Copy link
Member

wenshao commented Jun 1, 2024

https://github.com/alibaba/fastjson2/releases/tag/2.0.51
问题已修复,请用新版本

@wenshao wenshao closed this as completed Jun 1, 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 fixed
Projects
None yet
Development

No branches or pull requests

2 participants