[BUG]JSONPath.extractBUG
- Dominant language
- Java
- Stars
- 4.4k
- Forks
- 613
- Avg merge
- 1d 22h
- Merged PRs (30d)
- 6
Description
### 问题描述
*简要描述您碰到的问题。*
安全漏洞升级从1.2.83 升级到2.0.63 兼容包
### 环境信息
*请填写以下信息:*
- OS信息: [e.g.:CentOS 8.4.2105 4Core 3.10GHz 16 GB]
- JDK信息: [e.g.:Openjdk 1.8.0_312]
- 版本信息:[e.g.:Fastjson2 2.x.x]
### 重现步骤
*如何操作可以重现该问题:*
1.2.83版本可以获取到值Object nationTwoAbbr = JSONPath.extract(SPU_NATION_LIST, "$.nationTwoAbbr");
2.0.63 版本获取不到
```java
//可在此输入示例代码
private static final String SPU_NATION_LIST =
"[{\"nationTwoAbbr\":\"CN\"},{\"nationTwoAbbr\":\"IN\"}]";
/**
* 复现:旧代码路径 $.nationTwoAbbr。
* Fastjson1 能取出 CN,IN;Fastjson2 对数组根返回 null → 本断言失败,浮现不兼容。
*/
@Test
void legacyDollarPath_extractsSpuNationArea() {
System.out.println("fastjson=" + fastjsonVersion() + " path=$.nationTwoAbbr");
Object nationTwoAbbr = JSONPath.extract(SPU_NATION_LIST, "$.nationTwoAbbr");
System.out.println("$.nationTwoAbbr => " + nationTwoAbbr);
assertTrue(Utils.isNotEmpty(nationTwoAbbr),
"复现点:Fastjson2 下 $.nationTwoAbbr 对数组根为 null,fastjson=" + fastjsonVersion());
List spuNationArea = JSONArray.parseArray(JSON.toJSONString(nationTwoAbbr), String.class);
assertEquals("CN,IN", String.join(",", spuNationArea));
}
### 相关日志输出
*请复制并粘贴任何相关的日志输出。*
#### 附加信息
*如果你还有其他需要提供的信息,可以在这里填写(可以提供截图、视频等)。*
Contributor guide
Research direction
Start with the JSONPath.extract call and the legacyDollarPath_extractsSpuNationArea test shown in the issue, using the provided SPU_NATION_LIST input. Run the regression test against fastjson2 and verify that the $.nationTwoAbbr path returns CN and IN for the array root, matching the fastjson 1 behavior.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- java
- Domain
- backend
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Quiet
- Clarity
- Mostly clear
- Newbie friendliness
- 68/100