Skip to content

Commit

Permalink
fix JSONPath#extract, for issue #2584 #2585
Browse files Browse the repository at this point in the history
  • Loading branch information
wenshao committed May 16, 2024
1 parent 4478e86 commit 5893fc8
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 4 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
package com.alibaba.fastjson2.issues_2500;

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

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

public class Issue2584 {
@Test
public void testMutant1() {
JSONObject obj = JSONObject.of("data", JSONArray.of(1));
String str = JSON.toJSONString(obj);
assertEquals(JSONPath.eval(str, "$.data[0][0]"), JSONPath.eval(obj, "$.data[0][0]"));
}

@Test
public void testMutant2() {
JSONObject obj = JSONObject.of("data", JSONArray.of(1, 2));
String str = JSON.toJSONString(obj);
assertEquals(JSONPath.eval(str, "$.data[0][0]"), JSONPath.eval(obj, "$.data[0][0]"));
}

@Test
public void testMutant3() {
JSONObject obj = JSONObject.of("data", JSONArray.of(JSONObject.of("id", "1")));
String str = JSON.toJSONString(obj);
assertEquals(JSONPath.eval(str, "$.data[0][0]"), JSONPath.eval(obj, "$.data[0][0]"));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,6 @@ public void testMutant2() {
" \"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]"));
Expand All @@ -44,8 +42,6 @@ public void testMutant3() {
" \"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]"));
Expand Down

0 comments on commit 5893fc8

Please sign in to comment.