From f985b6a11abe0fecff1d6f763ddedcc40511d944 Mon Sep 17 00:00:00 2001 From: Sunwuyuan Date: Mon, 1 Dec 2025 20:20:17 +0800 Subject: [PATCH] Update validation logic for request body Allow empty arrays to pass validation while intercepting empty objects. --- routes/kv-token.js | 9 ++------- 1 file changed, 2 insertions(+), 7 deletions(-) diff --git a/routes/kv-token.js b/routes/kv-token.js index 72bcc31..c3c159d 100644 --- a/routes/kv-token.js +++ b/routes/kv-token.js @@ -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 = @@ -432,4 +427,4 @@ router.delete( }) ); -export default router; \ No newline at end of file +export default router;