1
1
mirror of https://github.com/ZeroCatDev/ClassworksKV.git synced 2025-12-07 21:13:10 +00:00

Update validation logic for request body

Allow empty arrays to pass validation while intercepting empty objects.
This commit is contained in:
Sunwuyuan 2025-12-01 20:20:17 +08:00 committed by GitHub
parent f0de2cd59b
commit f985b6a11a
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -356,12 +356,7 @@ router.post(
const {key} = req.params;
const value = req.body;
// 【修改点】允许空数组通过校验,但继续拦截真正的空对象 {}
// 如果 value 是空数组 []Object.keys 为 0但 !Array.isArray 为 false条件为 false -> 通过
// 如果 value 是空对象 {}Object.keys 为 0且 !Array.isArray 为 true条件为 true -> 拦截
if (!value || (Object.keys(value).length === 0 && !Array.isArray(value))) {
return next(errors.createError(400, "请提供有效的JSON值"));
}
// 获取客户端IP
const creatorIp =