shreemaan-abhishek opened a new pull request, #13314:
URL: https://github.com/apache/apisix/pull/13314
### Description
Follow-up to #13096 (which corrected the wording of the JSON-parse error
message in the AI prompt plugins). That patch left two nil-concatenation
hazards behind that turn the affected plugins into 500s instead of returning
the intended 4xx client error:
1. `core.request.get_body()` can return `nil` with `err == nil` for
**empty** request bodies. With:
```lua
return nil, { message = "could not get body: " .. err }
```
the concatenation crashes with `attempt to concatenate local 'err' (a nil
value)`.
2. `core.json.decode()` returning `nil` with `err == nil` is much rarer but
still possible, and the same concatenation hazard applies.
Affected files:
- `apisix/core/request.lua` — `get_json_request_body_table()`. The
`get_body()` branch already had an `(err or "request body is empty")` guard
from a previous patch; this PR adds the matching guard on the `json.decode()`
branch.
- `apisix/plugins/ai-prompt-template.lua` — `get_request_body_table()`. Both
branches need the guard.
- `apisix/plugins/ai-prompt-decorator.lua` — `get_request_body_table()`.
Both branches need the guard.
Reproduction (before this PR):
```
POST / HTTP/1.1
Content-Type: application/json
Content-Length: 0
```
with `ai-prompt-template` enabled returns 500 instead of the configured
"could not get body: request body is empty" message.
#### Which issue(s) this PR fixes:
Follow-up to #13096; no separate issue.
### Checklist
- [x] I have explained the need for this PR and the problem it solves
- [x] I have explained the changes or the new features added to this PR
- [ ] I have added tests corresponding to this change — *the existing
`t/admin/routes_request_body.t` exercises the nil-`err` empty-body path and now
correctly produces the configured error message; happy to add a focused
regression test in `t/plugin/ai-prompt-template.t` if reviewers want one.*
- [x] I have updated the documentation to reflect this change — *no doc
impact; behaviour is now the documented one.*
- [x] I have verified that this change is backward compatible
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]