Skip to content

[Bug]:使用编程式接口时,body传空对象字符串 {} 会触发占位符解析导致报错 #249

@CashinChen

Description

@CashinChen

依赖环境:

Java: 25
Forest: 1.8.0
Backend: httpclient
SpringBoot: 3.5.6

问题简述:

使用编程式接口时,传空对象字符串 {} 会触发占位符解析导致报错

如何复现:

Forest.post(url)
                        .contentTypeJson()
                        .addBody("{}")
                        .executeAsString();

会报错

com.dtflys.forest.exceptions.ForestIndexReferenceException: Index 0 out of bounds for arguments length 0

	[From Template]

	source: {}
	        ^^ Index 0 out of bounds for arguments length 0

	at com.dtflys.forest.mapping.MappingExpr.throwIndexReferenceException(MappingExpr.java:128)
	at com.dtflys.forest.mapping.MappingIndex.render(MappingIndex.java:31)
	at com.dtflys.forest.mapping.MappingUrlEncodedExpr.render(MappingUrlEncodedExpr.java:33)
	at com.dtflys.forest.mapping.MappingTemplate.renderExpression(MappingTemplate.java:776)
	at com.dtflys.forest.mapping.MappingTemplate.renderExpression(MappingTemplate.java:746)
	at com.dtflys.forest.mapping.MappingTemplate.render(MappingTemplate.java:801)
	at com.dtflys.forest.mapping.MappingTemplate.render(MappingTemplate.java:789)
	at com.dtflys.forest.reflection.TemplateVariable.getValue(TemplateVariable.java:18)

某个接口请求入参中有设置"{}"该字符串的要求
能否提供一个设置原生raw字符串body的方法,不包含任何占位符解析功能的。

预期结果:

.addBody("{}")不触发占位符解析逻辑,直接设置"{}"字符串到请求体

实际结果:

.addBody("{}")触发了解析占位符逻辑报错

截图或视频:

No response

最小可复现代码:

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions