Description
Environment information
Version: 2.2.0
Platform: Linux khalid 6.13.8-arch1-1 #1 SMP PREEMPT_DYNAMIC Sun, 23 Mar 2025 17:17:30 +0000 x86_64 GNU/Linux
Node.js version: v22.12.0
Any other relevant information:
What steps will reproduce the bug?
Our project used morgan for logging in this way app.use(morgan(jsonFormat, { stream: Logger.stream }));
morgan logging have a custom jsonFormat
function to customize our logs, inside it we use this line body: stringifyFields(JSON.parse(tokens.body(req, res)) ?? {}),
to log the body of the response, for requests that return no body we expect the tokens.body(req,res)
to return null or undefined but in the new version of body-parser the returned value is invalid json string instead of null or undefined so the JSON.parse throw exception because it can not parse it
the JSON.parse error:
SyntaxError: Unexpected token 'u', "
undefined" is not valid JSON
at JSON.parse (<anonymous>)
this is might be also tested by many ways other than that
Note: morgan version is the same, we didn't change it