feat: body-parser-2.x test (#13278)

* feat: body-parser-2.x test

* fix req.body
This commit is contained in:
Barış Soner Uşaklı
2025-03-27 11:29:37 -04:00
committed by GitHub
parent 57819810ce
commit 389bc062e3
4 changed files with 8 additions and 5 deletions

View File

@@ -45,7 +45,7 @@
"autoprefixer": "10.4.21",
"bcryptjs": "3.0.2",
"benchpressjs": "2.5.3",
"body-parser": "1.20.3",
"body-parser": "2.2.0",
"bootbox": "6.0.0",
"bootstrap": "5.3.3",
"bootswatch": "5.3.3",

View File

@@ -46,7 +46,7 @@ Posts.get = async (req, res) => {
Posts.getIndex = async (req, res) => {
const { pid } = req.params;
const { sort } = req.body;
const { sort } = req.body || {};
const index = await api.posts.getIndex(req, { pid, sort });
if (index === null) {

View File

@@ -287,7 +287,9 @@ middleware.validateAuth = helpers.try(async (req, res, next) => {
middleware.checkRequired = function (fields, req, res, next) {
// Used in API calls to ensure that necessary parameters/data values are present
const missing = fields.filter(field => !req.body.hasOwnProperty(field) && !req.query.hasOwnProperty(field));
const missing = fields.filter(
field => req.body && !req.body.hasOwnProperty(field) && !req.query.hasOwnProperty(field)
);
if (!missing.length) {
return next();

View File

@@ -62,8 +62,9 @@ module.exports = function (middleware) {
return await finishLogin(req, user);
} else if (user.hasOwnProperty('master') && user.master === true) {
// If the token received was a master token, a _uid must also be present for all calls
if (req.body.hasOwnProperty('_uid') || req.query.hasOwnProperty('_uid')) {
user.uid = req.body._uid || req.query._uid;
const body = req.body || {};
if (body.hasOwnProperty('_uid') || req.query.hasOwnProperty('_uid')) {
user.uid = body._uid || req.query._uid;
delete user.master;
return await finishLogin(req, user);
}