-
Notifications
You must be signed in to change notification settings - Fork 495
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix JSONPath#extract, for issue #2585
- Loading branch information
Showing
2 changed files
with
54 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
53 changes: 53 additions & 0 deletions
53
core/src/test/java/com/alibaba/fastjson2/issues_2500/Issue2585.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
package com.alibaba.fastjson2.issues_2500; | ||
|
||
import com.alibaba.fastjson2.JSONPath; | ||
import org.junit.jupiter.api.Test; | ||
|
||
import static org.junit.jupiter.api.Assertions.assertEquals; | ||
|
||
public class Issue2585 { | ||
@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"; | ||
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]")); | ||
} | ||
} |